943,547 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 703
  • PHP RSS
Aug 15th, 2008
0

Page Searcher

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blood08 is offline Offline
11 posts
since Jun 2007
Aug 15th, 2008
0

Re: Page Searcher

Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Aug 15th, 2008
0

Re: Page Searcher

Note sure exaclty how I would use it? Can you explain more please
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blood08 is offline Offline
11 posts
since Jun 2007
Aug 15th, 2008
0

Re: Page Searcher

Click to Expand / Collapse  Quote originally posted by blood08 ...
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
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Aug 15th, 2008
0

Re: Page Searcher

thanks for all the help!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blood08 is offline Offline
11 posts
since Jun 2007
Aug 15th, 2008
1

Re: Page Searcher

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

PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 posts
since Aug 2008
Aug 15th, 2008
0

Re: Page Searcher

Even better, this will make my job 10 times easier.

Click to Expand / Collapse  Quote originally posted by langsor ...
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

PHP Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
blood08 is offline Offline
11 posts
since Jun 2007
Aug 15th, 2008
0

Re: Page Searcher

Click to Expand / Collapse  Quote originally posted by blood08 ...
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
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Aug 15th, 2008
0

Re: Page Searcher

Click to Expand / Collapse  Quote originally posted by R0bb0b ...
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
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: need help in send and email
Next Thread in PHP Forum Timeline: how to tell php to set into Utf-8?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC