php preg_replace function


php preg_replace function

Perform a regular expression search and replace


$what_to_replace = array(“/a/”,”/b/”,”/c/”);

$replace_with = array(“dog”,”cat”,”rat”);

print preg_replace($what_to_replace, $replace_with, “1a2b3b”);

// Out put of this function will be 1dog2cat3rat




  1. mikesmobile said

    Thanks for your ‘howto’ on the preg_replace PHP function. It cleared things up. Maybe you can help on something. I have a string that I am trying to search for and replace particular sections of said string. Here’s what I have:

    $str = “”;

    I need to replace ‘’ with the real path of the directory (i.e. /home/usr/www/).

  2. Yazınız için teşekkür ederim

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: