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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.