Hello, I have write a simple search page for my sit(testing!)
Now I am trying to highlight my search keyword from the search result.
Not going to use java so I am thinking to use something like preg_replace
But the problem is I dont where should I start with.
As you can see the code below(Ive took out some part of it), the output will be a table and displaying all the result which will match $term.
So now, I am trying to implement the preg_replace
$hterm = preg_replace($term, '<span class="highlight">$term<\/span>', ????);
what should I use to replace the ???? ?
Ive read the preg_replace from the PHP dot net but I still a bit confuse in my case...
Thank you for your help and sorry for my English.
<?php
$term = $_POST['term'];
if(preg_match("/^[ a-zA-Z0-9]+/", $_POST['term'])){
include("connect.php");
mysql_select_db ("12345"); //the db is not real
$sql = mysql_query("select * from 12345 where name like '%$term%' or info like '%$term%' or id like '%$term%' ");
if (mysql_num_rows($sql) > 0)
{
while ($row = mysql_fetch_array($sql))
{
echo 'Your search keyword(s): ' .$term;
echo '<table border="1">';
echo '<tr BGCOLOR=#D8D8D8><td><b>ID:</b></td> <td>' .$row['id'].'</td></tr>';
echo '<tr BGCOLOR=#D8D8D8><td><b>title:</b></td> <td>' .$row['title'].'<br></tr>';
echo '<tr BGCOLOR=#D8D8D8><td><b>Category:</b></td> <td>' .$row['category'].'<br></tr>';
echo '<tr BGCOLOR=#D8D8D8><td><b>Time:</b></td> <td>' .$row['time'].'<br></tr>';
echo '<br><br>';
echo '</table>';
}
}else
echo 'Your search keyword(s): ' .$term .'<p>Nothing! : </p>';
}else
echo '<p>Please enter a search query</p>';
?>