Professional Web Applications Themes

[PHP] highlighting multi term search results - PHP Development

[email]jonas_webergmx.ch[/email] wrote: > Am Sonntag, 07.09.03 um 14:11 Uhr schrieb Catalin Trifu >> output: this is just a <b>te</b>st >> (after the first term is highlighted the second one can't be found >> anymore.) > > but how to work around it?? Highlight the longest words first? -- ---John Holmes... Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url] php|architect: The Magazine for PHP Professionals [url]www.phparch.com[/url]...

  1. #1

    Default Re: [PHP] Re: highlighting multi term search results

    [email]jonas_webergmx.ch[/email] wrote:
    > Am Sonntag, 07.09.03 um 14:11 Uhr schrieb Catalin Trifu
    >> output: this is just a <b>te</b>st
    >> (after the first term is highlighted the second one can't be found
    >> anymore.)
    >
    > but how to work around it??
    Highlight the longest words first?

    --
    ---John Holmes...

    Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]

    php|architect: The Magazine for PHP Professionals [url]www.phparch.com[/url]
    John W. Holmes Guest

  2. #2

    Default [PHP] Re: highlighting multi term search results

    Am Sonntag, 07.09.03 um 21:17 Uhr schrieb John W. Holmes:
    >>> output: this is just a <b>te</b>st
    >>> (after the first term is highlighted the second one can't be found
    >>> anymore.)
    >> but how to work around it??
    >
    > Highlight the longest words first?
    I don't think that would change anything. A search for "te est" then
    highlights "test" into "t<b>est</b>" and "te" can't be found anymore.

    thanks anyway!!
    j

    snip 8<
    <?
    function highlight($src_terms, $src_terms_int, $result) {
    $i = 0;
    while ($i < $src_terms_int) {
    $result = preg_replace('/('.$src_terms[$i].')/si',
    '<b>'.$src_terms[$i].'</b>', $result);
    $i++;
    }
    return $result;
    }

    $search = "te est"; // user input to search for
    $src_terms = explode(" ", $search);
    $src_terms_int = count($src_terms);

    $result = "this is just a test"; // result from database

    print highlight($src_terms, $src_terms_int, $result);
    ?>

    output: this is just a <b>te</b>st
    (after the first term is highlighted the second one can't be found
    anymore.)

    someone has an idea how to work around this?

    thanks for your effort!
    jonas


    ps: please also let me know if you know of a website that might help, i
    didn't find anything useful. thanks!
    Jonas_weber @ Gmx . Ch Guest

  3. #3

    Default Re: [PHP] Re: highlighting multi term search results

    On Mon, 8 Sep 2003 00:11:09 +0200, Jonas_weber Gmx . Ch
    <jonas_webergmx.ch> wrote:
    > Am Sonntag, 07.09.03 um 21:17 Uhr schrieb John W. Holmes:
    >
    >>>> output: this is just a <b>te</b>st
    >>>> (after the first term is highlighted the second one can't be found
    >>>> anymore.)
    >>> but how to work around it??
    >>
    >> Highlight the longest words first?
    >
    > I don't think that would change anything. A search for "te est" then
    > highlights "test" into "t<b>est</b>" and "te" can't be found anymore.
    Why not just allow for bold tags in the search term? What I mean is, I
    think you can get the results you want by allowing any number of open or
    close bold tags between each letter of the search term.

    <?php
    function highlight($src_terms, $src_terms_int, $result) {
    $i = 0;
    while ($i < $src_terms_int) {
    $termWithOptionalBold = preg_replace('/(.)/', '(<\/?b>)
    *\1',$src_terms[$i]);
    $result = preg_replace('/(<\/?b>)*('.$termWithOptionalBold.')(<\/?b>)
    */si', '<b>\2</b>', $result);
    $i++;
    }
    return $result;
    }
    ?>
    --
    Lee O'Mara
    Lee O'Mara Guest

  4. #4

    Default [PHP] Re: highlighting multi term search results

    Am Montag, 08.09.03 um 04:21 Uhr schrieb Lee O'Mara:
    > Why not just allow for bold tags in the search term? What I mean is, I
    > think you can get the results you want by allowing any number of open
    > or close bold tags between each letter of the search term.
    i thought so too (but i had no idea how to code it); this must be a
    solution.
    i've tested your function like this:

    <?
    function highlight($src_terms, $src_terms_int, $result) {
    $i = 0;
    while ($i < $src_terms_int) {
    $termWithOptionalBold = preg_replace('/(.)/', '(<\/?b>)
    *\1',$src_terms[$i]);
    $result = preg_replace('/(<\/?b>)*('.$termWithOptionalBold.')(<\/?b>)
    */si', '<b>\2</b>', $result);
    $i++;
    }
    return $result;
    }

    $search = "te est"; // user input to search for
    $src_terms = explode(" ", $search);
    $src_terms_int = count($src_terms);
    $result = "this is just a test"; // result from database

    print highlight($src_terms, $src_terms_int, $result);
    ?>

    but it didn't highlight anything.

    btw, the bold tag in this example is used to simplify it and stands for
    something like <span class="highlight"></span> what makes it even
    trickier, i guess.

    thanks for your help!
    jns
    Jonas_weber @ Gmx . Ch Guest

  5. #5

    Default Passing query parameter which has value "###"

    I passed value
    main.php?name=$name&id=$id&id1=$id1 to next page
    where $id has value "###"
    In the next page I was not able to get the $id and $id1 values
    and I am able to get the two values $id1 and $name when I used
    main.php?name=$name&id1=$id1
    What might be the problem?

    -Thanks & regards,
    Murugesan
    Murugesan Guest

  6. #6

    Default RE: [PHP] Passing query parameter which has value "###"

    try this


    main.php?name=" . $name . "&id=" . $id . "&id1=" . $id1 . "


    HTH

    -----Original Message-----
    From: murugesan [mailto:mukeshgcthotpop.com]
    Sent: Monday, September 08, 2003 1:05 PM
    To: [email]php-generallists.php.net[/email]
    Subject: [PHP] Passing query parameter which has value "###"


    I passed value
    main.php?name=$name&id=$id&id1=$id1 to next page
    where $id has value "###"
    In the next page I was not able to get the $id and $id1 values
    and I am able to get the two values $id1 and $name when I used
    main.php?name=$name&id1=$id1
    What might be the problem?

    -Thanks & regards,
    Murugesan

    --
    PHP General Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php
    Angelo Zanetti Guest

  7. #7

    Default Re: [PHP] Passing query parameter which has value "###"

    At 13:04 8-9-03, you wrote:
    >I passed value
    >main.php?name=$name&id=$id&id1=$id1 to next page
    >where $id has value "###"
    >In the next page I was not able to get the $id and $id1 values
    >and I am able to get the two values $id1 and $name when I used
    >main.php?name=$name&id1=$id1
    >What might be the problem?

    The # in a url is used for the in-page anchors, e.g. if you have an anchor
    in your page <a name="chapter2"></a>, then a url such as page.html#chapter2
    will jump to that location in the page. So the part after the # is cut off
    by the browser, i suppose.


    Try this:
    <?php
    echo '<a href="main.php?name='.$name.'&id='. urlencode($id).'">';
    ?>
    This changes the # to a code (% followed by some number)

    (check urlencode in the manual)
    Chris Hayes Guest

  8. #8

    Default Re: [PHP] Passing query parameter which has value "###"

    Thanks for the reply.It is working

    -Murugesan
    ----- Original Message -----
    From: "Chris Hayes" <chayesantenna.nl>
    To: "murugesan" <mukeshgcthotpop.com>; <php-generallists.php.net>
    Sent: Monday, September 08, 2003 5:15 PM
    Subject: Re: [PHP] Passing query parameter which has value "###"

    > At 13:04 8-9-03, you wrote:
    > >I passed value
    > >main.php?name=$name&id=$id&id1=$id1 to next page
    > >where $id has value "###"
    > >In the next page I was not able to get the $id and $id1 values
    > >and I am able to get the two values $id1 and $name when I used
    > >main.php?name=$name&id1=$id1
    > >What might be the problem?
    >
    >
    > The # in a url is used for the in-page anchors, e.g. if you have an anchor
    > in your page <a name="chapter2"></a>, then a url such as
    page.html#chapter2
    > will jump to that location in the page. So the part after the # is cut off
    > by the browser, i suppose.
    >
    >
    > Try this:
    > <?php
    > echo '<a href="main.php?name='.$name.'&id='. urlencode($id).'">';
    > ?>
    > This changes the # to a code (% followed by some number)
    >
    > (check urlencode in the manual)
    >
    Murugesan Guest

Similar Threads

  1. Verity pdf search term highlighting
    By acdhirr in forum Macromedia ColdFusion
    Replies: 2
    Last Post: April 12th, 12:08 PM
  2. highlighting search terms results
    By leegold2 in forum PHP Development
    Replies: 2
    Last Post: October 26th, 01:22 AM
  3. Highlighting Search Entries in Webhelp
    By jojust in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: September 3rd, 09:38 PM
  4. highlighting multi term search results
    By Jonas_weber @ Gmx . Ch in forum PHP Development
    Replies: 0
    Last Post: September 7th, 12:05 PM
  5. [PHP] search result highlighting / regexp voodoo
    By Lee O'Mara in forum PHP Development
    Replies: 0
    Last Post: September 3rd, 07:15 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139