SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Apr 2003
    Location
    nville
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can i emphasize what was searched for?

    PHP Code:

    <?php
    //get the results and store them in $result
    $result mysql_query ("SELECT * FROM news WHERE storytext LIKE '%$search%'");
    //run the while loop
    while($r=mysql_fetch_array($result))
    {    
        
    //grab the result
        
    $storytext=$r["storytext"];
        
    //print it out
        
    echo "<p>$storytext";
        
        echo 
    "<br><br><hr>";
        
    }
    //else nothing is found
    //else
    //{
    //    echo "Nothing found";
    //}
    ?>
    this is my search function. if i search for a word it will return any blog entry that has that word. it'd be cool if i could get it to return the entire entry (like it already does) but with the word that was searched for in bold. could anyone show me a way to do that?

  2. #2
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess the easist way is to just do

    PHP Code:
    $storytext str_replace($search"<b>$search</b>"$storytext); 

  3. #3
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use str_replace()

    $blog = str_replace( $word, "<font color='red'>$word</font>', $blog );

    [img]images/smilies/biggrin.gif[/img] (with all this help, how could you go wrong!)
    John

  4. #4
    SitePoint Member tahjah's Avatar
    Join Date
    Mar 2003
    Location
    US
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo str_ireplace($search"<b>$search</b>"$storytext); 
    Keep in mind that if you are searching by multiple/separate keywords that you'll have a different implementation.

    Edit: Eh, two posts should be enough

  5. #5
    SitePoint Member
    Join Date
    Apr 2003
    Location
    nville
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to all three!!! of you. and in about 10 minutes. what a great site this is.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •