Hey, I am creating a site and I need to be able to check the existence of a chunk of html coding on a specific url specified by a user. I'll have a table in a MySQL DB with the following information: ...userID.........URL............................activated ......1.............www. digitalpoint.com..........1...... ......2.............www. msn.com...................1...... etc... Obviously this is just an example. Anyway so I need a script to take each row, check the url for the existance of a chunk of html coding, and then update the activated field to the appropriate value - 1 if the code is there, 0 if not. I was wondering if someone could give me advice or tell me a good resource to learn how to do this. Thanks Hodge
You would need to loop through the table one line at a time. For each line you then use fopen on the url and then use the following to detect if the string exists. ?php $mystring = 'abc'; $findme = 'a'; $pos = strpos($mystring, $findme); // Note our use of ===. Simply == would not work as expected // because the position of 'a' was the 0th (first) character. if ($pos === false) { echo "The string '$findme' was not found in the string '$mystring'"; } else { echo "The string '$findme' was found in the string '$mystring'"; echo " and exists at position $pos"; } ?> PHP: Now you can update the DB with 1 or 0 as appropriate.
Thanks for that Just to clarify is $mystring= fopen( URL FROM DB ) and $findme the piece of coding I want to find on that page?
Go to sourceforge.net and look for a class called Snoopy. The short Readme file will show you exactly how to grab all the links from a webpage and stuff them into an array. This, plus some simple code to run through your database, should be all you need.