Jump to content

removing php from webpage source code


captaingrassholm

Recommended Posts

Hi,

 

I am using the following regular expression to try and seperate php elements from plain xhtml:

$arr = split("\<\?[^(?>)]+\?\>",$text);

This works fine if I don't include any html closing tags in $text, otherwise not, excuse my undoubted ignorance but I thought putting ?> in brackets (escaping these makes no difference) would require a match for anything that was not a ? followed by a >, i.e. a script closing tag?

Can anyone point out my no doubt obvious mistake as I have tried all sorts.

Thanks,

Chris

Link to comment
https://forums.phpfreaks.com/topic/129250-removing-php-from-webpage-source-code/
Share on other sites

No character classes interpret those brackets literally. So you're looking for anything that isn't an opening bracket, question mark, closing angled bracket, or closing bracket.

 

You want to use either negative look-ahead or lazy modifiers... Lazy should get the job done faster... but it's still inefficient regex.

 

<\?.*?\?>

 

You'll want to execute that with the 's' flag ( dot matches newline )

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.