Re: The difference between ereg and preg?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dave M G wrote:
PHP List,

Recently I wrote a piece of code to scrape data from an HTML page.

Part of that code deleted all the unwanted text from the very top of the page, where it says "<!DOCTYPE", all the way down to the first instance of a "<ul>" tag.

That code looks like this:
ereg_replace("<!DOCTYPE(.*)<ul>", "", $htmlPage);

It works fine. But I noticed that on almost all the tutorial pages I looked at, they just about always used preg_replace, and not ereg_replace.

It seemed that the main difference was that preg_replace required forward slashes around the regular expression, like so:
preg_replace("/<!DOCTYPE(.*)<ul>/", "", $htmlPage);

But that didn't work, and returned an error.

Since ereg was working, though, I figured I would just stick with it.

Still, I thought it worth asking:

Is there any reason why either ereg or preg would be more desirable over the other?

Why does the ereg work for the command above, but preg not?

Thank you for any advice.

--
Dave M G

Everybody missed one important difference. The PCRE module is compiled into PHP by default. The POSIX module is not included by default. Therefore it's not safe to use the POSIX regular expression module if you intend to deploy your code on another system.

Regards, Adam.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux