Trying to highlight search results from mySQL query

Hi, I’ve been trying various methods to highlight searched-for text in a results page using PHP and a mYSQL query.

I get an output of “Array” when using some code I found for this (which other users seem to think works fine, so I’m clearly missing something)

This is what I have so far: (_KeyWords is the input on the form on the preceding search page, containing the text that users are searching for). The DiaryEntry field in the db is the text that contains the matching term(s).

Not only is it just outputting “Array” (which is apparently because of the explode function- but it doesn’t work if I remove it either) but it also ignores my .highlight class even though I’ve defined it and the page is pointing correctly to the stylesheet.


$searchvar = explode(" ", trim($_POST['_KeyWords'])); //puts each space separated word into the array.

while ($row= mysql_fetch_array($result)) {
  $diaryentryid = $row["DiaryEntryID"];
  $diaryentry = $row["DiaryEntry"];
  $dateadded = $row["DateAdded"];
  $addedby = $row["AddedBy"];

//Date formatting for output in the summary screen
$dateoutput = date("F j, Y", strtotime($dateadded) );

    foreach($searchvar as $var) $diaryentry = str_replace($var, '<span class="highlight">'.$var."</span>", $diaryentry);
    $diaryentry = str_replace($searchvar, '<span class="highlight">'.$searchvar."</span>", $row['DiaryEntry']);

echo '
<tr>
<td align="left" width="75">' . $diaryentryid . '</td>
<td align="left" width="450">' . $diaryentry . '</td>
<td align="left" width="100">' . $addedby . '</td>
<td align="left" width="125">' . $dateadded . '</td>
<td align="left" width="50"><a href="editdiaryentry-details.php?DiaryEntryID=' . $diaryentryid . '">Edit</a></td>
</tr>' ;
$count++ ;
}

Any ideas?