For the website I'm working on, I've included a "search the site" section. Once the user searches a keyword or a phrase, the php processes all the content in the mysql database and prints out the title, content and a link to the page with the article containing that specific text.
I'll include the most relevant part of the code from that php file:
<?php
// get results from database
$result = mysql_query($query) or die("Couldn't execute query");
// display the results
$count=0;
while ($row = mysql_fetch_array($result)) {
if ($count != 5) {
$count++;
$hometitle = $row["home_title"];
$homecontent = nl2br($row["home_content"]);
echo "<p><b><u>Results</u></b><br><br>Title:<br>$hometitle<br><br>Content:<br>$homecontent<br>" . "<a href=\"../index.php\">See Full Content</a></p>";
}
}
?>
Sorry for that messy looking "echo". But what I want to do is for the keyword which is searched for to be highlighted in the results.
I'm guessing the algorithm for it be something like converting the resulting value into an array, boldening the keywords then again changing it into a string before printing again. However, I've not been able to do this successfully.
Help Please!