Re: Search in PhP
| From: | Nadim Attari | Date: | Wed, 30 Jul 2003 10:27:09 +0000 |
| Subject: | Re: Search in PhP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-157503@lists.php.net to get a copy of this message | ||
> i have a site in php but not using database i want to
> add the search facilty in that site means user can
> search into the contents of the site .so how can i do
> that in php without using database.waiting for ur soon
> reply
Hello,
- First of all try to get a list of all files (php, html, etc)
- for each file,
-- get the contents, and then strip_tags($theContentOfOneFile);
-- try to find whether the keyword to be found is in the contents,
e.g. use substr_count() store the number of occurences in an array
$searchArray = array('fileName' => 'number_of_occurences')
- sort the array, e.g. arsort($searchArray)
- display the results
foreach($searchArray as $fileName => $occurences)
{
if ($occurences == 0) break;
// display as you wish
echo "Found in $fileName $occurences times<br>";
}
Hope it helps,
Nadim Attari