str_replace()不使用带有搜索参数变量的while循环

$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)'s output:

array(1) {
    ["words"]=> string(5) "hello "
}
array(1) {
    ["words"]=> string(5) "you "
}

It doesn't replace any string in the title But if I put the values directly like "hello" in the place of $fix then it works fine.

Through some troubleshooting with you, we ascertained that it was the space coming from the database field. To correct the issue code should be changed to

$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;

Ideally strings should be trimmed as they get inserted to the database to prevent this issue.