i can not do the trick of displaying -+50 characters before and after search 
keyword in the search results...also it does not give accurate positions of the 
words I search (just for me to see). what's wrong below? 
$keyword1=$_POST['keyword1']; //i get keyword from a search form
$trimmed1 = trim($keyword1); 

$query=mysql_query("SELECT * FROM newsa WHERE title LIKE '%$trimmed1%' OR par1 
LIKE '%$trimmed1%' OR body LIKE '%$trimmed1%' ORDER BY date DESC LIMIT 100");

while ($row = mysql_fetch_array($query)) {

$string=$row['title'].$row['par1'].$row['body']; //in order to search the 
keyword in title + first paragraph + the rest of the article, first I combine 
the whole article into one string... am I doing right?

$pos = strpos($string, $trimmed1); //i can not get the corrcet position...plus 
if there is more than one keyword in string, which one is supposed to be 
returned?

echo "$pos"."<br/>"; //this is just to see the position number for my info
$pos = $pos - 50;
$end = $pos + 50; //actually this is of no use am I wrong? because in substr 
the last item is the length of string to be displayed, not the end point...so i 
wrote 100 below...
$output = substr($string, $pos, 100);
echo "$output";. 


      

[Non-text portions of this message have been removed]

Reply via email to