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? Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/ 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. Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/#findComment-244889 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. Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/#findComment-244891 Share on other sites More sharing options...
john010117 Posted May 3, 2007 Share Posted May 3, 2007 $_GET will work. Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/#findComment-244894 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 Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/#findComment-244895 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'; } ?> Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/#findComment-244898 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)) Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/#findComment-244901 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. Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/#findComment-244905 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. Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/#findComment-244909 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'; } ?> Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/#findComment-244912 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'; Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/#findComment-244930 Share on other sites More sharing options...
techiefreak05 Posted May 4, 2007 Author Share Posted May 4, 2007 haha. silly typos. Link to comment https://forums.phpfreaks.com/topic/49909-check-if-a-certain-string-is-in-a-page/#findComment-244936 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.