Page Searcher

Reply

Join Date: Jun 2007
Posts: 11
Reputation: blood08 is an unknown quantity at this point 
Solved Threads: 0
blood08 blood08 is offline Offline
Newbie Poster

Page Searcher

 
0
  #1
Aug 15th, 2008
How would you make PHP search a website for a certain word and then return a true or false?

Is there a function built into php already?
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Page Searcher

 
0
  #2
Aug 15th, 2008
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 11
Reputation: blood08 is an unknown quantity at this point 
Solved Threads: 0
blood08 blood08 is offline Offline
Newbie Poster

Re: Page Searcher

 
0
  #3
Aug 15th, 2008
Note sure exaclty how I would use it? Can you explain more please
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Page Searcher

 
0
  #4
Aug 15th, 2008
Originally Posted by blood08 View Post
Note sure exaclty how I would use it? Can you explain more please
Found this example here http://www.weberdev.com/get_example-4606.html
  1. <?php
  2. $ch = curl_init() or die(curl_error());
  3. curl_setopt($ch, CURLOPT_URL,"http://search.msn.com/results.aspx?q=test&FORM=MSNH");
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5. $data1=curl_exec($ch) or die(curl_error());
  6. echo "<font color=black face=verdana size=3>".$data1."</font>";
  7. echo curl_error($ch);
  8. curl_close($ch);
  9. ?>

and rather than echoing the data to the page you just use string and array functions to parse and search through the $data1 variable.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 11
Reputation: blood08 is an unknown quantity at this point 
Solved Threads: 0
blood08 blood08 is offline Offline
Newbie Poster

Re: Page Searcher

 
0
  #5
Aug 15th, 2008
thanks for all the help!
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: Page Searcher

 
1
  #6
Aug 15th, 2008
Also, assuming your server host didn't disable this feature (enabled by default) for security reasons (allow_url_fopen) you can also get the contents of a file via URL with ...

file (returns file as array, split on linebreaks)
fopen (opens read/write/append file-handle)
file_get_contents (returns whole file as string)

Write ups of these functions
file -- http://us.php.net/manual/en/function.file.php
fopen --- http://us.php.net/manual/en/function.fopen.php
file_get_contents -- http://us.php.net/manual/en/function...t-contents.php
allow_url_fopen -- http://us2.php.net/manual/en/filesys...llow-url-fopen

Just thought you might like to know

  1. <?php
  2. $word = 'search'; // found
  3. //$word = 'phat'; // not found
  4. $file = file_get_contents( 'http://www.google.com' );
  5. if ( preg_match( "/$word/i", $file ) ) {
  6. print "word: $word";
  7. } else {
  8. print "phat";
  9. }
  10. ?>
Last edited by langsor; Aug 15th, 2008 at 2:07 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 11
Reputation: blood08 is an unknown quantity at this point 
Solved Threads: 0
blood08 blood08 is offline Offline
Newbie Poster

Re: Page Searcher

 
0
  #7
Aug 15th, 2008
Even better, this will make my job 10 times easier.

Originally Posted by langsor View Post
Also, assuming your server host didn't disable this feature (enabled by default) for security reasons (allow_url_fopen) you can also get the contents of a file via URL with ...

file (returns file as array, split on linebreaks)
fopen (opens read/write/append file-handle)
file_get_contents (returns whole file as string)

Write ups of these functions
file -- http://us.php.net/manual/en/function.file.php
fopen --- http://us.php.net/manual/en/function.fopen.php
file_get_contents -- http://us.php.net/manual/en/function...t-contents.php
allow_url_fopen -- http://us2.php.net/manual/en/filesys...llow-url-fopen

Just thought you might like to know

  1. <?php
  2. $word = 'search'; // found
  3. //$word = 'phat'; // not found
  4. $file = file_get_contents( 'http://www.google.com' );
  5. if ( preg_match( "/$word/i", $file ) ) {
  6. print "word: $word";
  7. } else {
  8. print "phat";
  9. }
  10. ?>
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Page Searcher

 
0
  #8
Aug 15th, 2008
Originally Posted by blood08 View Post
Even better, this will make my job 10 times easier.
Ya, I guess Curl is a bit overkill for what you want to do with it, but it is a good thing to learn though as the options are limitless.
If you ever decide to play with it, here is a pretty good tutorial:
http://www.phpbuilder.com/columns/ia...n20050525.php3
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: Page Searcher

 
0
  #9
Aug 15th, 2008
Originally Posted by R0bb0b View Post
Ya, I guess Curl is a bit overkill for what you want to do with it, but it is a good thing to learn though as the options are limitless.
If you ever decide to play with it, here is a pretty good tutorial:
http://www.phpbuilder.com/columns/ia...n20050525.php3
Thanks R0bb0b,

I've actually been avoiding learning CURL since it seems complicated, and I'm lazy, but I know I should figure it out too. I bookmarked that tutorial.

Cheers
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC