Need Help..on search engine
How should I juz pick up the line that contained the searched word by using regex??
My code...
if ($type == "Articles")
{
$search_article = "where (title LIKE '%$search%' or body LIKE '%$search%')";
$sql = "SELECT title, body from article $search_article limit 10";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$s = $search;
$row[title]=preg_replace("/($s)/i","<font class=search>\1</font>",$row[title]);
$row[body]=preg_replace("/($_s)/i","<font class=search>\1</font>",$row[body]);
printf ("title: %s Name: %s", $row["title"], $row["body"]);
}
mysql_free_result($result);
}
By using this, I pick up the searched word and highlighted with CSS...
But can the regex be changed and only pick up the line that contained the searched word??
Coz, an article can be long, and what if the searched word is at the bottom of the article??
You know what i mean....
Coz if the searched word is at the bottom, it can be searched but not show up the highlighted searched word...
Can anybody help me with this!!!!
I want to use juz regex and pick out 100 characters of the line that contained the searched word...something like google... 🙂
Thanx....