Help me in this work

Discussion in 'PHP' started by balasun, Aug 4, 2008.

  1. #1
    Hello all,
    
    I need ur help in below work,
    
    I need to made search operation depending upon keywords typed in the text box, and also in results i highlighted with red the search keywords. The problem in this is the search keywords are highlighted with case sensitive. That is, when i type 'html' to search, in the result 'HTML' is not highlighted.
    
    I need to highlighted the result with an incase sensitive keyword.
    
    My coding is as follows:
    [PHP]$searchtxt=strtolower(stripslashes($_REQUEST[txtSearch]));
        //$searchtxt1=addslashes(htmlspecialchars($searchtxt));
        //echo $searchtxt1=addslashes(htmlspecialchars($searchtxt));
       $sql="SELECT * FROM page_content  WHERE (lower(modelno) LIKE '%$searchtxt%') or (lower(prodname) LIKE '%$searchtxt%') or (lower(proddesc) LIKE '%$searchtxt%') or (lower(prodfeature) LIKE '%$searchtxt%') or (lower(prodspec) LIKE '%$searchtxt%')";
        $res=mysql_query(getPagingQuery($sql))or die(mysql_error());
        $num=mysql_num_rows($res);
        $i=1;
        if($num!=0)
        {
        while($row=$db->fetch_array($res))
        {
        
        $pname=stripslashes($pname);
        $pdesc=stripslashes($row[proddesc]);
         $pdesc=str_replace($searchtxt,"<b><font color=red>".$searchtxt."</font></b>",$pdesc);
        echo "<p align='justify'><a href=getcontent.php?mcid=$row[mcid]&scid=$row[scid]><font size='2'><u>$i.$row[modelno].&nbsp;$pname</u></font></a></span><br/><br>$pdesc<br/></p>";
        $i=$i+1;
        }
    PHP:

     
    balasun, Aug 4, 2008 IP
  2. somanweb

    somanweb Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hello balasun,

    Use the str_ireplace() function instead of str_replace().

    it will ignore the case-sensitive.
     
    somanweb, Aug 5, 2008 IP
  3. balasun

    balasun Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for ur reply,
    i used str_ireplace() in my coding ,it's working good in text. but when i type number like 32" HD TV then in result does not highlighed 32" HD TV does not highlighted.

    Is there any way for these?
     
    balasun, Aug 5, 2008 IP
  4. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm not sure I understand you, give a more specific example (maybe some sample code). I guess you get a syntax error, cause you didn't escape the character " in the search term. Make it \" and try again
     
    xlcho, Aug 5, 2008 IP