Hey all! I am really stuck here and could use some help. Im having troubles replacing text inside of a string. I am trying to loop through an array of names and wrapping html around the value if its found. Everything works great untill I do a for each???
Heres the example:
function stri_replace($replacer,$replacement,$string) {
$lowercase_replacer = strtolower($replacer);
// Make all the words we are replacing lowercase
$string = str_replace($replacer,$lowercase_replacer,$string);
// Replace all occurences
$string = str_replace($lowercase_replacer,$replacement,$string);
return $string;
}
$contents = "frost frost2 frost3 frost4";
$prog = explode(" ", trim($contents));
while (list(, $value) = each ($prog)) {
echo "Value: $value<br>\n";
$replacer = $value;
$replacement = "<a href=$value>$value</a>";
$string = "frost is the best.";
$final_value = stri_replace($replacer,$replacement,$string);
}
print ("$final_value");
What I get:
Value: frost
Value: frost2
Value: frost3
Value: frost4
frost is the best.
What the heck is going on?