Page 1 of 1

preg_match vs eregi

Posted: Tue May 21, 2002 3:20 am
by ILoveJackDaniels
I'm running a script that does a large number of eregis, eregi_replaces etc, and heard that preg_match and preg_replace as well as str_replace can all be faster. As the script is running quite slowly, I've played around with these a little and had a look at the manual, but am a little confused.

Should this not return true if $word has a hyphen in it? For some reason it's throwing up errors and I can't for the life of me figure out why....

Code: Select all

if (preg_match("-",$word)) {

Re: preg_match vs eregi

Posted: Thu May 23, 2002 4:33 pm
by duke9
ILoveJackDaniels wrote:

Code: Select all

if (preg_match("-",$word)) {
http://www.php.net/manual/en/ref.pcre.php - The expression should be enclosed in the delimiters, a forward slash (/), for example.

So you have to write it like this

Code: Select all

if (preg_match("/-/",$word))