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 = (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.

Spoody
  • 2,852
  • 1
  • 26
  • 36

1 Answers1

0

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.

René
  • 6,006
  • 3
  • 22
  • 40
Simon R
  • 3,732
  • 4
  • 31
  • 39