'PHP search result highlight string not working

please i need your advice. A have a search result, i want highlight search keyword in the text.

Here i perform search (searchTest.php)

$sql = "SELECT * FROM xxxx WHERE title LIKE ? OR text1 LIKE ? OR datum LIKE ? order by (datum) desc";
try {
      $stmt = $connect->prepare($sql);
      $stmt->execute(["%".$_POST["search"]."%", "%".$_POST["search"]."%", "%".$_POST["search"]."%"]);
      $resultsNEW = $stmt->fetchAll();
      if (isset($_POST["ajax"])) { echo json_encode($resultsNEW); }

Here i handle search results, that work fine.

 if (isset($_POST["search"])) {
    require "searchTest.php";

    if (count($resultsNEW) > 0) { 
        foreach ($resultsNEW as $r) {

Here i try print the result with string replacement, but its not working

 echo str_replace ($r, "<span style='background-color:yellow'>$_POST[search]</span>", $r["text1"]);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source