strings and search

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
barak
Forum Newbie
Posts: 2
Joined: Tue May 20, 2008 6:25 am

strings and search

Post by barak »

Hello,
My mother lang is not English and I am sorry on the mistakes .

I am working on a searching robot.
I have a little problem showing the result.
this is the base code:

Code: Select all

 
$file =file_get_contents($url); 
         if (strstr($file2,$word[$i]))
        {
         $ex =  strstr($file ,$word[$i]);//find the word in the text
         $num = strlen($word[$i]);//the size of the word i am looking(in int)
         $pri =  substr($ex , 0 , $num);// return  $num charts  from the the $file
         $pri2 =  substr($ex , 0 , 20);// return  20 charts from the the $file
         $line = STRPOS($file,$word[$i]);// line number of the word
        echo " The word '<b>{$word[$i]}</b>' found in line $line"; 
        echo "<pre>         the full sentance : '<b>$pri2</b>'<br></pre>";
        }
        else 
        {
        echo "The word {$word[$i]} wasnt found in the page <b>$url</b>";
        }
 
The problem is that he is searching all over the page..include HTML code..
And I dont want him to search in the HTML code...
how do i fix it?
Ty
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: strings and search

Post by yacahuma »

maybe you can try html purifier to remove all html stuff
htmlpurifier.org
konrad
Forum Newbie
Posts: 3
Joined: Tue May 20, 2008 4:10 pm

Re: strings and search

Post by konrad »

You can use strip_tags function (http://uk3.php.net/manual/pl/function.strip-tags.php).

Code: Select all

 
 $file = strip_tags(file_get_contents($url));
 
Just take into account some valuable informations are kept in the html code (ie. alternative text, titles).

Hope that helps.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: strings and search

Post by yacahuma »

but i dont think strip_tags will remove everything. read strip_tags documentation
Post Reply