Russia Posted December 8, 2009 Share Posted December 8, 2009 I am trying to find out what this is called. Its like when you get a webpages contents, and if certain words that you are looking for are found then it will say something, if the words you are looking for are not found, then say something else. What is that called? I think curl is used for it. Example: if (preg_match("/User is Online./i", $pagedata)) { echo = "user is online"; } else (preg_match("/User is Offline./i", $pagedata)) { echo = "user is offline"; } I have no idea what its called or how to do it. Quote Link to comment https://forums.phpfreaks.com/topic/184469-dont-know-what-its-called/ Share on other sites More sharing options...
mikesta707 Posted December 8, 2009 Share Posted December 8, 2009 um, what you are describing is simply a Regular Expression match. You could use Curl, or you could simply use file_get_contents() to get the data from the page. Quote Link to comment https://forums.phpfreaks.com/topic/184469-dont-know-what-its-called/#findComment-973799 Share on other sites More sharing options...
Russia Posted December 8, 2009 Author Share Posted December 8, 2009 How would i do that? Can you show me how I would write it up so it gets it from a website. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/184469-dont-know-what-its-called/#findComment-973801 Share on other sites More sharing options...
mikesta707 Posted December 8, 2009 Share Posted December 8, 2009 $pageInfo = file_get_contents("whatever page you want"); As far as Curl, you will have to wait for another user to answer that, as it is not my forte, you can also look up Curl examples on the manual Quote Link to comment https://forums.phpfreaks.com/topic/184469-dont-know-what-its-called/#findComment-973803 Share on other sites More sharing options...
Russia Posted December 8, 2009 Author Share Posted December 8, 2009 So something like this? <?php $pagedata = file_get_contents("http://example.com/profile/user_bucket.php"); if (preg_match("/User is Online./i", $pagedata)) { echo = "user is online"; } else (preg_match("/User is Offline./i", $pagedata)) { echo = "user is offline"; } ?> So basically if the user named Bucket is online on his profile and it looks for the word "online" or "offline" it will come back and tell me if he is? Quote Link to comment https://forums.phpfreaks.com/topic/184469-dont-know-what-its-called/#findComment-973805 Share on other sites More sharing options...
mrMarcus Posted December 8, 2009 Share Posted December 8, 2009 file_get_contents grabs the page/file that is the argument, and converts the entire page to a string which is in your case: $pagedata you can then run a regex against that variable ($pagedata) to check for matches of anything that might be on/in that page/string($pagedata). what regex is run is up to you since nobody here knows what will be available within $pagedata. Quote Link to comment https://forums.phpfreaks.com/topic/184469-dont-know-what-its-called/#findComment-973810 Share on other sites More sharing options...
Russia Posted December 8, 2009 Author Share Posted December 8, 2009 Something like? $handle = fopen("http://www.example.com/", "rb"); $data = stream_get_contents($handle); fclose($handle); $find = "Find me"; $pos = strpos($data, $find); if ($pos === 0) { // Not found... echo "Not found..."; } else { // Found! echo "Found!!!!"; } Quote Link to comment https://forums.phpfreaks.com/topic/184469-dont-know-what-its-called/#findComment-973813 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.