Jump to content

replacing ereg_replace and eregi_replace with preg_replace


Bl4ckMaj1k

Recommended Posts

    $customer_contact_id = preg_replace("`", "", $customer_contact_id);

 

Am I doing something wrong? Every page that used the eregi_function, I changed to have it utilize the preg_function (because I saw a Youtube video telling me to do so). Now, every variable I perform the above on acts as if it doesn't exist. This has totally destroyed my system. What do I need to do here to fix things?

preg functions need pattern delimiters:

 

$customer_contact_id = preg_replace("/`/", "",  $customer_contact_id);

 

However, if you don't need regex, this is easier and faster:

 

$customer_contact_id = str_replace("`", "",  $customer_contact_id);

preg functions need pattern delimiters:

 

$customer_contact_id = preg_replace("/`/", "",  $customer_contact_id);

 

However, if you don't need regex, this is easier and faster:

 

$customer_contact_id = str_replace("`", "",  $customer_contact_id);

 

Worked just fine, thanks!!

 

The video told you to do that because eregi has been deprecated since 5.3.

 

Hmm....why do they deprecate functions anyway? eregi_replace still got the job done...what made someone make another function which does the exact same thing?

PCRE (Perl Compatible Regular Expressions) used in preg functions are generally faster than and have additional functionality beyond POSIX which is used in the ereg functions.  Plus, with the popularity of Perl, they may be more widely known and used.

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.