Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Page search

  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts

    Page search

    Hi guys! For some time agi I saw a thread where 2 people both posted their search scritps, and one said that his was faster than the other. However now I can't find that thread, so I'll ask again:

    How do I make a search script that will, when you enter a keyword into the search field and press search, highlight the word(s) on the page?

  • #2
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Here's the thread

    Scan a page

    Smthing like this
    Last edited by matak; 08-02-2007 at 08:27 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    Thanks Matak, for the script! But...Again I have a problem.

    For reference, this is my searchscript.php file:
    Code:
    <?php
    $uzorak = $_POST['query'];
    //use post to get $uzorak variable
    
    $tapeti = file_get_contents("frequsedwords.php");
    
    
    $tagovi    = array();
    
    work    ($uzorak, $tapeti);
    function    work($uzorak, $tapeti)    {
    
    $duzina        = strlen($uzorak);
    $velicina    = strlen($tapeti);
    
    $b = array();
    $a = 0;
    while    ($a <= $velicina){
    $newstr    =    substr($tapeti, $a, $duzina);
    
    if ($newstr == $uzorak){
        $tagovi[]= $a;
    }
    elseif ($a == $velicina && !empty($tagovi)){
        uredi_tagove($tagovi, $tapeti, $duzina);
    }
    elseif ($a == $velicina && empty($tagovi)) {
        echo "sorry no matches found";
        break;
    }
    $a++;
    }
    }
    function uredi_tagove($tagovi, $tapeti, $duzina){
        
        $newstring ="";
        $count = count($tagovi);
        $nextchar = 0;
        for($i = 0;$i<$count;$i++)
         {
            $newstring .= substr($tapeti,$nextchar,$tagovi[$i]-$nextchar);
            $newstring .= "<strong>". substr($tapeti,$tagovi[$i],$duzina) ."</strong>";
            $nextchar = $tagovi[$i]+$duzina;
         }
         $newstring .= substr($tapeti,$nextchar);
         print $newstring;
    }
    
    
    ?>
    And this is my form HTML code:
    Code:
    <form action="searchscript.php" method="POST" >
    <input type="text" name="query" >
    <input type="submit" value="search" >
    </form>
    The problem is, that when I input a word like "FMC" and press search, nothing happens other than the word dissapears and the calender I have on the left hand site only shows some code. Try it out here: http://www.xflightx.port10.com/frequsedwords.php

    I only want the script to highlight the word I search for, nothing else.

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    for me when i press submit it brings up so no matches

  • #5
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    First script is caps sensitive, that can be changed with using strtolower() function.

    Test it first with using some text file and getting it with file_get_contents, and make sure that path for file get contents is correct.

    Other than that i can't see the problem, couse for me script works just fine

  • #6
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    Hi again!

    I found that this wasn't quite the script I was looking for... (thanks for the try, Matak).

    So, I have found another one. I'll continue here: http://www.codingforums.com/showthre...495#post596495

    Thanks for the help, guys!
    Last edited by CaptainB; 08-04-2007 at 09:28 PM.


  •  

    Posting Permissions

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