Search the site?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartic
    New Member
    • May 2007
    • 150

    Search the site?

    [HTML]<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Search </title>
    </head>

    <body>
    <form id="form1" name="form1" method="post" action="index.p hp">
    <input name="Search_IN " type="text" id="Search_IN" maxlength="44" />
    <input type="submit" name="SearchBTN " id="SearchBTN" value="Search" />
    </form>[/HTML]
    [PHP]<?php

    $YourSearch=str tolower($_POST['Search_IN']);
    $text=ucfirst($ YourSearch);


    if($_POST['SearchBTN']){
    if(!ereg("^[a-zA-Z ]{4,44}$",$YourS earch)){
    echo "Please Wright Rorrect Data";
    exit;
    }else{
    echo "Your Search results for {$text} is :<br />";
    if ($handle = opendir('../Search')) {
    while (false !== ($file = readdir($handle ))) {
    if($file=="." || $file==".." || $file=="_notes" || $file=="Result. php" || $file=="index.p hp"){
    //--------------------------------------------------------------
    }else{
    //get the files information
    $All_Files .= $file."*";
    $All_Files_Data =explode("*",$A ll_Files);
    }
    }
    closedir($handl e);
    }
    }

    for($i=0;$i<cou nt($All_Files_D ata);$i++){
    if(is_file($All _Files_Data[$i])){
    if(strchr(strto lower(file_get_ contents($All_F iles_Data[$i])),$YourSearch) ){
    echo "<a href='$All_File s_Data[$i]'>$All_Files_Da ta[$i]</a><br />";
    }
    }else if(is_dir($All_ Files_Data[$i])){
    echo "The dir is : {$All_Files_Dat a[$i]}<br />";
    echo "<a href='$All_File s_Data[$i]'>$All_Files_Da ta[$i]</a><br />";
    }
    }
    }

    ?>[/PHP]
    [HTML]</body>
    </html>[/HTML]

    This code to search on my site but im having problem with the code,when the user search the site i need to tell the user if he did't fined any result.
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    Originally posted by smartic
    This code to search on my site but im having problem with the code,when the user search the site i need to tell the user if he did't fined any result.
    And that's the hard part...? Why don't you keep track of how many records were displayed? Maybe check the value of $i after the for loop.

    Comment

    Working...