I'm trying to do a preg_replace on mysql results.
I have this:
$string = 'The quick brown fox jumped over the lazy dog.';
//(with in the table "brown" in the Pattern field and "blue" in the Replacement field)
$username="user";
$password="password";
$database="database";
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM table";
$result=mysql_query($query) or die (mysql_error());
$num = mysql_num_rows($result) or die (mysql_error());
$i=0;
while ($i < $num) {
$patterns[$i] = mysql_result($result,$i,"Patterns")';
$i++;
}
$i=0;
while ($i < $num) {
$replacements[$i] = mysql_result($result,$i,"Replacements");
$i++;
}
ksort($patterns);
ksort($replacements);
echo preg_replace($patterns, $replacements, $string);
?>
but the script outputs the replaced line without any changes, brown is not replaced with blue.
What am I doing wrong?
Hope anyone can help!
Cheers,
Vincent