Jump to content

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 )

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.