Jump to content

extract data from web page


rupam_jaiswal

Recommended Posts

Yeah, my definition was a bit loose.

 

characters that are within the pattern need to be escaped (for the most part this is true.. but there are oddball exceptions.. but I digress)

 

I can't imagine a case where you don't have to escape delimiters in the pattern. Or were you talking about characters in general?

Nope, I am talking about delimiter characters in a pattern :)

 

Consider the following for example:

 

$str = 'Some text... <_FOO_> some more text <_BAR_> and yet again some more!';
$str = preg_replace('<<_[^_]+_>>', '<_XX_>', $str); // note there is no need to escape < and > inside the delimiters in this scenario...
echo $str; // Output: Some text... <_XX_> some more text <_XX_> and yet again some more!

 

This is admittedly a stupid (and rare) example. But it shows that under some circumstances, it might not require escaping. In this case, there is a caveat... there has to be matching opening and closing < and > characters inside the < > delimiters.. if there is a mismatch, then you'll probably need to escape (otherwise you'll get either 'Unknown modifier' or 'No ending matching delimiter' warnings).

 

I personally advise against using opening / closing matching punctuation as delimiters (such as <...>, {...}, (...) or [....]). Too much confusion / trouble for what it's worth IMO.

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.