I'm trying to write something that look at a given string, checks if there are any php tags present and if not, it'll stick em on. I was just gonna do it with a match and then do the concatenation separately (not using preg_replace).
I got the basic idea working with this regexp.
but I need to make it more complex. I've been playing around all day to no avail. It needs to recognise when the php tags are sandwiched inside single or double quotes... tricky heh?preg_match('/<\?php(.|\s)*?\?>/', $source))
Examples and outputs (true=php tags do exist, false=php tags need adding):
Hope I have given a good enough idea of what I need to do. I'll post a better regexp if I get anywhere.This returns true:
<?php
echo $var;
?>
This returns true
<span>This isn't php</sapn>
<?php
echo 'But this is!';
?>
This returns false (That's the twist - those PHP tags aren't actually acting as PHP they are part of a string withing the PHP)
echo "An opening php tag looks like this <?php and a closing one looks like this ?>";
This also returns false (single quotes)
echo 'An opening php tag looks like this <?php and a closing one looks like this ?>';
But This returns true
<?php
echo 'An opening php tag looks like this <?php and a closing one looks like this ?>';
?>
Hope somebody can offer some help *cough* cough*