Forum Moderators: coopster

Message Too Old, No Replies

Searching for a string in a URL

         

asantos

2:09 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



Hi. I need to search for a string (lets say "b55d57a3b1c9a125b896dbb249eb7e4b") on a specific website (lets say example.com).

This is the only solution i came with.

$url = 'http://example.com';
$search = 'b55d57a3b1c9a125b896dbb249eb7e4b';
$data = file_get_contents(urlencode($url));
if(strpos($data,$search)) {
echo 'OK!';
} else {
echo 'Not found...';
}

Is there a better and quickier way to do this?

[edited by: eelixduppy at 4:13 pm (utc) on Mar. 15, 2007]
[edit reason] use example.com [/edit]

joelgreen

4:50 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



Your solution is ok. You may want to strip tags before strpos if $search could possibly match some html tag. Like $search = "table".

Some would say sockets would do this job faster (fsockopen), but I doubt. Some time ago tested on loop with about 500 pages, and there was no significant time difference (1 or 2 seconds).

asantos

10:25 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



joelgreen, thanks! all clear now.