Jump to content

Recommended Posts

I've been Googling for a regexp to match php-blocks in a html-file. But Googling for "php regexp html" doesn't yield very much useful... I still believe the regexp has been written at least once...

 

The idea being to strip out php-from a html-file, but store the stripped out blocks for later...

 

I would need something like /<\?php (.*?)\?>/. But I would like it to match all possible php-blocks, see http://www.php.net/manual/en/language.basic-syntax.phpmode.php

 

And it should also handle strings etc. which might contain the string "?>". I don't even know which ways a block of php can contain "?>" without it closing the php-block...

'/(<\?(?:php)?.*?\?>)/i'

 

 

but ofcourse.. that would result in errors if for whatever reason you're trying to like

 

echo '?>';

 

in your php but thats rare I suppose, but you could use some sort of look ahead to be sure you get the very last one, or at the very least an atomic group.. good luck :D

 

oh and you're using php? use preg_match_all instead of preg_match for greedy searches

oh and you're using php? use preg_match_all instead of preg_match for greedy searches

 

If by greedy you mean preg_match returns first match vs. preg_match_all returns every match it finds, then sure, you can call that a greedy search.  Though that might confuse people, considering that that term is used to describe quantifiers, and that is not the same kind of greedy...

 

OP:

Not really sure what you're overall goal here is, but if you're scraping pages, php will not be in the file unless it's somehow commented out, outside of php tags to begin with. 

 

 

 

oh.. coz the first language I learned RegEx in was mIRC, and in mIRC or (mSL) the RegEx had modifyers, much like /i or /s but one of them was /g for 'greedy' or 'global' search so I just got used to calling it a greedy search, my bad :)

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.