Q:

to find and replace the string in php

I have got a number of values by a foreach loop. Now I want to check each the values with a string.
My string is "http://www.example.com/TantraProjects/Ranjit/nt_plugin"
I have the values like written below:
http://blogsearch.google.com/blogsearch?scoring=d&partner=wordpress&q=link:http://www.example.com/TantraProjects/Ranjit/nt_plugin/

http://blogsearch.google.com/blogsearch_feeds?scoring=d&ie=utf-8&num=10&output=rss&partner=wordpress&q=link:http://www.example.com/TantraProjects/Ranjit/nt_plugin/

link:http://www.example.com/TantraProjects/Ranjit/nt_plugin/ - Google Blog Search

Now I want to change all the values, replacing http://www.example.com/TantraProjects/Ranjit/nt_plugin with MY NEW PATH.
How can I replace the string using php?

A:

str_replace
And please, use google, there are thousands of answers for that question online. :)
Also if you want to embed a links in URLs like that:

http://blogsearch.google.com/blogsearch?scoring=d&partner=wordpress&q=link:http://www.example.com/TantraProjects/Ranjit/nt_plugin/

You need to use urlencode on the URL you pass after &q=.
So basically:
$string = "http://blogsearch.google.com/blogsearch?scoring=d&partner=wordpress&q=MY_NEW_PATH";
$output = str_replace('MY_NEW_PATH', "link:".urlencode('http://www.example.com/TantraProjects/Ranjit/nt_plugin'), $string); //$search , $replace, $subject

