regex - Help with Regular expression (PHP, preg_replace) -


I have to do a preg_replace on all pH tags in a string, as well as PHP tags.

For example, if the content of the file was:

  Hey there! & Lt ;? Php some_stuff ()? & Gt; Whoa!  

All should be omitted:

  Hey there! Whoa!  

This is my code:

  $ file_contents = file_get_contents ('somefilename.php'); $ Regex = '# ([& lt ?? php] (. *) [\? & Gt;]) #E'; $ File_contents = preg_replace ($ regex, '& lt; Generated Content & gt; & gt;', $ file_contents);  

unsuccessful.

My regular expression skills are poor, someone please fix my regex. Thank you.

Try this regex:

  # & lt; \ *. *? \? & Gt; #  

Should work on a less tag (without 'php').

I think the main issue with your effort was that you need to avoid question marks with backslash, and that you were using the brackets of those classes where you should not be Was there. Square bracket means "Choose one of these letters".


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -