I need your help in creating a search result page for my site. Its a simple php cms site simply fetching content from mysql.
Using a simple query to fetch search
$search = $_GET["search"];
$search = preg_replace('#[^0-9]#i','',$_GET['search']);
$searchresult = mysql_query ("SELECT * FROM pages WHERE pgcontent LIKE '%$search%'");
while ($row = mysql_fetch_array($searchresult))
{
echo '<h3>' . $row["PageTitle"] . '</h1>';
echo '<p>' . $row["PageContent"] . '</p><br /><br />';
}
What i want to do is not to display the whole page content, just the line where any word matches with the search term … or just the first few lines of that page where the search term was found.
Friends can you help me in doing this please? it will be a big favor … thank you
You could run post processing on
$row["PageContent"]Something like
Where you begin your snippet 100 characters from the beginning of the matched term and end it 100 characters after the beginning of the term. Obviously you tune this to whatever you want but this is the basic idea.
If I missed the point let me know and I may update.