$query1 = mysqli_query($cone,"SELECT words FROM banlist ORDER BY words") or die(mysql_error());
while($row = mysqli_fetch_array($query1, MYSQLI_ASSOC)) {
$fix = (string)$row['words'];
$title = str_replace($fix, "-", $title);
}
echo $title;
var_dump($row)
的输出:
array(1) {
["words"]=> string(5) "hello "
}
array(1) {
["words"]=> string(5) "you "
}
它不会替换标题中的任何字符串但是如果我将"hello"
之类的值直接放在$fix
的位置,那么它可以正常工作。
答案 0 :(得分:0)
通过一些故障排除,我们确定它是来自数据库字段的空间。要更正问题代码,请更改为
$query1 = mysqli_query($cone,"SELECT words FROM banlist ORDER BY words") or die(mysql_error());
while($row = mysqli_fetch_array($query1, MYSQLI_ASSOC)) {
$fix = trim($row['words']);
$title = str_replace($fix, "-", $title);
}
echo $title;
理想情况下,字符串应在插入数据库时进行修剪,以防止出现此问题。