php preg_replace function

preg_replace

php preg_replace function

Perform a regular expression search and replace

<?php

$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

?>

Advertisements

2 Comments »

  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 = “http://www.mywebsite.com/sub/directory/”;

    I need to replace ‘http://www.mywebsite.com’ 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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: