Forum Moderators: coopster
$find=dog;
$replace=dogg;
OUTPUT doggg.
If I were to tell it to:
$find=e;
$replace=erik;
$words="easy does it"
OUTPUT "erikasy doeriks it"
function findreplace() {
extract($GLOBALS); $find = $_POST['find'];
$replace = $_POST['replace'];
// use str_ireplace() for case insensitive find replace in php5.
$words = str_replace($find, $replace, $words);
return $words;
}
Should I be using a different function?
Thanks!
Hmmm.. it depends on what you mean by 'exact match'. From what you have it is actually an exact match, but it lacks conditions. For example if you want to replace a instances of 'e' but the condition is it must be the first or last character of the string - then you need something more powerful like regular expressions. There are a couple of functions for this, check out [php.net...] for starters (it has other functions listed on this page also).