Site Search Engine

    Date: 02/25/07 (PHP Community)    Keywords: php, rss, xml, web

    I was wondering if there is a good place to use a php
    site search engine that will search your web site.
    I found a grep one and put it here:
    http://www.cardeologist.com/search.php
    but, it will show some files I don't want it to, like my
    sitemap.xml and my rss file, robots.txt file, etc.
    Is there a better one or a way to disallow files?
    And if I wanted to add subdomains, can I do that?




    Search cardelogist.com:





    " method="post">
    value="" size="20"
    maxlength="30"/>



    if (! empty($searchstr)) {
    // empty() is used to check if we've any search string.
    // If we do, call grep and display the results.
    echo '

    ';
    // Call grep with case-insensitive search mode on all files
    $cmdstr = "grep -i $searchstr *";
    $fp = popen($cmdstr, 'r'); // open the output of command as a pipe
    $myresult = array(); // to hold my search results
    while ($buffer = fgetss($fp, 4096)) {
    // grep returns in the format
    // filename: line
    // So, we use split() to split the data
    list($fname, $fline) = split(':', $buffer, 2);
    // we take only the first hit per file
    if (! defined($myresult[$fname])) {
    $myresult[$fname] = $fline;
    }
    }
    // we have results in a hash. lets walk through it and print it
    if (count($myresult)) {
    echo '

      ';
      while (list($fname, $fline) = each ($myresult)) {
      echo "
    1. $fname : $fline
    2. \n";
      }
      echo '

    ';
    } else {
    // no hits
    echo "Sorry. Search on $searchstr
    returned no results.
    \n";
    }
    pclose($fp);
    }
    ?>

    Source: http://community.livejournal.com/php/545756.html

« regular expressions || double posts »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home