I got this simple thing , it basically works , but there's something about it that does not sound right so, I got this:
我得到了这个简单的东西,它基本上是有效的,但有一些关于它的东西听起来不对,所以我得到了这个:
$text = $_GET['text'];
$sitechoose=mysql_query("SELECT * FROM site");
while($change=mysql_fetch_array($sitechoose)) {
$o = $change['original'];
$r = $change['changed'];
$messages = str_replace($o, $r, $text);
}
echo messages;
So the replace thing works , but only replaces the $o and $r of the last databse result , any ideas why ? thanks!
所以替换的东西可行,但只替换最后数据库结果的$ o和$ r,任何想法为什么?谢谢!
EDIT: $text supposed to be smiles / badwords etc... while in mysql table original would be the smile :) amd changed would be
编辑:$文本应该是微笑/坏词等...而在mysql表原来将是微笑:) amd改变将是
1 个解决方案
#1
0
Currently, your $messages
variable is a simple string. You need to make $messages
an array. Your code should look like this instead:
目前,您的$ messages变量是一个简单的字符串。你需要将$ messages作为一个数组。你的代码应该是这样的:
$text = $_GET['text'];
$sitechoose = mysql_query("SELECT * FROM site");
$messages = array();
while ($change = mysql_fetch_array($sitechoose)) {
$o = $change['original'];
$r = $change['changed'];
$messages[] = str_replace($o, $r, $text);
}
echo $messages;
Assigning to $messages[]
will push a new element onto the end of the array.
分配给$ messages []会将新元素推送到数组的末尾。
#1
0
Currently, your $messages
variable is a simple string. You need to make $messages
an array. Your code should look like this instead:
目前,您的$ messages变量是一个简单的字符串。你需要将$ messages作为一个数组。你的代码应该是这样的:
$text = $_GET['text'];
$sitechoose = mysql_query("SELECT * FROM site");
$messages = array();
while ($change = mysql_fetch_array($sitechoose)) {
$o = $change['original'];
$r = $change['changed'];
$messages[] = str_replace($o, $r, $text);
}
echo $messages;
Assigning to $messages[]
will push a new element onto the end of the array.
分配给$ messages []会将新元素推送到数组的末尾。