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

From what I understand there are 2 schools of thought on regular expressions. There is the Perl (Perl Compatible Regular Expressions - preg) group and the POSIX (ereg) group. from the little I know they do the same thing but with different symbols for things.

References:
http://www.php.net/regex
http://www.php.net/pcre
--

life is a game... so have fun.

-- 
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