tcpalmer Posted November 17, 2009 Share Posted November 17, 2009 I want to be able to tell if a string is in an html page. For example, I want to see if <h1>Sagan-Man</h1><br/> is in the source for http://xkcd.com/663/ and then be able to run additional code if it is. Quote Link to comment https://forums.phpfreaks.com/topic/181861-solved-find-string-in-page/ Share on other sites More sharing options...
MadTechie Posted November 17, 2009 Share Posted November 17, 2009 like this <?php $html = file_get_contents("http://xkcd.com/663/"); $find = "<h1>Sagan-Man</h1><br/>"; if(stripos($html,$find) !== false){ echo "found"; } Quote Link to comment https://forums.phpfreaks.com/topic/181861-solved-find-string-in-page/#findComment-959125 Share on other sites More sharing options...
tcpalmer Posted November 17, 2009 Author Share Posted November 17, 2009 I am getting: Parse error: parse error, unexpected T_STRING in /home/content/t/c/p/tcpalmer/html/test.php on line 3 Note I changed the find string to what I will actually be searching for on a different page. <?php $html = file_get_contents("http://xkcd.com/663/"); $find = "<TD CLASS="dddefault">0</TD>"; if(stripos($html,$find) !== false){ echo "found"; } I think it is because of the other quotation marks in the string I am searching for. Quote Link to comment https://forums.phpfreaks.com/topic/181861-solved-find-string-in-page/#findComment-959128 Share on other sites More sharing options...
cags Posted November 17, 2009 Share Posted November 17, 2009 The syntax highlighting of the forum shows up your problem. You are trying to use a double quotes in a string that is delimited (started and ended) with a double quote. You will need to either escape them or change the delimiters to single quotes.... $find = "<TD CLASS=\"dddefault\">0</TD>"; // or $find = '<TD CLASS="dddefault">0</TD>'; Quote Link to comment https://forums.phpfreaks.com/topic/181861-solved-find-string-in-page/#findComment-959133 Share on other sites More sharing options...
tcpalmer Posted November 17, 2009 Author Share Posted November 17, 2009 Thank you guys both for your help so far. Earlier the function stripos worked, now it doesn't so I replaced it with strpos. Earlier file_get_contents for the https page, but now that is not working either. You do not have to be logged into anything to access this https page. Any ideas? I checked with my hosting provider and they didn't do anything. I am running PHP version 4.x Quote Link to comment https://forums.phpfreaks.com/topic/181861-solved-find-string-in-page/#findComment-959382 Share on other sites More sharing options...
MadTechie Posted November 17, 2009 Share Posted November 17, 2009 stripos is for PHP5+, why are you on PHP 4 ? PHP 6 is out soon! as for https pages whats the exact problem? maybe a cURL or socket connection would be better! Quote Link to comment https://forums.phpfreaks.com/topic/181861-solved-find-string-in-page/#findComment-959397 Share on other sites More sharing options...
tcpalmer Posted November 17, 2009 Author Share Posted November 17, 2009 I upgraded to PHP 5.2.5 and everything works now. Thank you for your help MadTechie. Quote Link to comment https://forums.phpfreaks.com/topic/181861-solved-find-string-in-page/#findComment-959424 Share on other sites More sharing options...
MadTechie Posted November 17, 2009 Share Posted November 17, 2009 I'll mark this as solved, you could (un)solved it by clicking "topic solved" bottom left Quote Link to comment https://forums.phpfreaks.com/topic/181861-solved-find-string-in-page/#findComment-959527 Share on other sites More sharing options...
mraza Posted November 17, 2009 Share Posted November 17, 2009 stripos is for PHP5+, why are you on PHP 4 ? PHP 6 is out soon! as for https pages whats the exact problem? maybe a cURL or socket connection would be better! sorry for offtopic but PHP 6 is coming out wow i need to learn fast then Quote Link to comment https://forums.phpfreaks.com/topic/181861-solved-find-string-in-page/#findComment-959535 Share on other sites More sharing options...
MadTechie Posted November 17, 2009 Share Posted November 17, 2009 Well it was announced late 2005, and yet theirs no release date (that i know of) a few things to keep in-mind, when developing (don't rely on magic_quotes or register_globals and update ereg's to preg's here is a list of changes in PHP6 magic_quotes, register_globals, register_long_arrays,safe_mode are all removed YAY removed ereg (update to preg people) Improved Unicode support Namespaces (well that's now in 5.30) Quote Link to comment https://forums.phpfreaks.com/topic/181861-solved-find-string-in-page/#findComment-959551 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.