Free PHP Tutorials

home
Stay at Home and Learn

str_replace( )

 
Computer Tutorials List

 

 

 

 

 

This allows you to replace one string with another. The syntaxt is:

str_replace($look_for, $change_to, $search_text, match_count);

The last one, match_count, is optional. It's counts how many matches it has found.

In the example below, we're looking for "explore" and want to replace it with "explode".

$search_text = "The explore function";
$look_for = "explore";
$change_to = "explode";

print $search_text . "<BR>";
$changed_text = str_replace($look_for, $change_to, $search_text);

print $changed_text;

So you're looking for one string in the search text, and replacing it with another.