techiefreak05 Posted May 3, 2007 Share Posted May 3, 2007 hello, i looked at file(), and file_get_contents() to get this job done.. but i dont see how i can use it to see if certain string is present in the web page. any help? Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 What job? Please elaborate, and post some code if necessary. Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted May 3, 2007 Author Share Posted May 3, 2007 I just need some code that goes to a url, and checks whether a given string is located within the file. thats it. Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 $_GET will work. Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted May 3, 2007 Author Share Posted May 3, 2007 sorry i meant this... have a script go to this url: http://www.site.com/index.html and look in the source for a certain string for ex. :"skn388h3fnn3w8n", and if its found anywhere in the source of the file, return true Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 3, 2007 Share Posted May 3, 2007 depends on which version of php you have... <?php $file = 'PATH/TO/FILE'; if (function_exists('file_get_contents')) { $string = file_get_contents($file) } else { $fp = fopen($file,'rb'); $string = fread($fp,filesize($file)); fclose($fp); } if (preg_match('/ASTRING/i',$string)) { echo 'found string'; } ?> Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted May 3, 2007 Author Share Posted May 3, 2007 so what does the '/ASTRING/i' part mean in this: if (preg_match('/ASTRING/i',$string)) Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 4, 2007 Share Posted May 4, 2007 It means to replace that with the string you are looking for. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 4, 2007 Share Posted May 4, 2007 it means 'search the whole string and if you find ASTRING in there return true. // are regular expression delimiters and the ending i means make it case insensitive. Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted May 4, 2007 Author Share Posted May 4, 2007 yes, file_get_contents does work on my server.. so i have this.. but it returns "string not found" ... <?php $file = 'htp://myspace.com'; //Might this be the problem? does external URLs work? $string = file_get_contents($file); if(preg_match('/Home/i',$string)){ echo 'found string'; }else{ echo 'string not found'; } ?> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 4, 2007 Share Posted May 4, 2007 $file = 'htp://myspace.com'; surely should be $file = 'http://myspace.com'; Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted May 4, 2007 Author Share Posted May 4, 2007 haha. silly typos. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.