#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Jan 13, 2012 11:17:57 GMT -8
Greetings, I have not written any RegExp in a long time, so forgive my slowly getting back into it. I am trying to remove PHP blocks from an HTML/XML file. The best RegExp I can come up with tis this: <\?php(.*?)\?> However, I believe this is having trouble because of the closing "?". If I remove the closing tag, ("<\?php(.*?)") it just matches the opening tag. How can I match the tags and all of the code in between? P.S. I understand that not matching anything that contains a PHP tag in a string (for example: echo "?>" is a lot harder, but this is not an issue in this application. - RedBassett
|
|
inherit
16846
0
Nov 19, 2012 15:20:20 GMT -8
Chris
3,036
December 2003
cddude
|
Post by Chris on Jan 13, 2012 11:31:02 GMT -8
Just a hunch, but I feel like linebreaks might be an issue. Try this instead?
<\?php([.\n\r]*?)\?>
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Jan 13, 2012 11:37:35 GMT -8
Just a hunch, but I feel like linebreaks might be an issue. Try this instead? <\?php([.\n\r]*?)\?> Still didn't work I considered linebreaks before, but couldn;t find much on them. Here is a test line I am using: echo preg_replace('/<\?php([.\n\r]*?)\?>/', '', $source); $soruce is the output of file_get_contents. The file is a mix of PHP, HTML, and some custom code (plaintext).
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Jan 23, 2012 16:22:00 GMT -8
No need for the parenthesis, since you aren't using the contents in the replace.
Try this:
echo preg_replace('/\<\?php.*?\?\>/sU', '', $source);
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Jan 25, 2012 22:48:45 GMT -8
No need for the parenthesis, since you aren't using the contents in the replace. Try this: echo preg_replace('/\<\?php.*?\?\>/sU', '', $source); Thanks, I think this is what I needed!
|
|