preg_match vs eregi

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ILoveJackDaniels
Forum Commoner
Posts: 43
Joined: Mon May 20, 2002 8:18 am
Location: Brighton, UK

preg_match vs eregi

Post 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)) {
duke9
Forum Newbie
Posts: 7
Joined: Thu May 23, 2002 4:17 pm

Re: preg_match vs eregi

Post 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))
Post Reply