EsOne Posted December 8, 2009 Share Posted December 8, 2009 I decided to ask this question here. I have a code that scrapes a page for info, then in turn echos something when a certain data compnent is found in the scrape. <html> <head><?php $data = file_get_contents('http://www.gaiaonline.com/chat/gsi/index.php?v=json&m=[[6500%2C[1]]%2C[6510%2C[%225175269%22%2C0%2C1]]%2C[6511%2C[%225175269%22%2C0]]%2C[6512%2C[%225175269%22%2C0]]%2C[107%2C[%22null%22]]]&X=1260296981'); $regex = '/"state":"(.+?)","player_count"/'; preg_match($regex,$data,$match); var_dump($match); if ($match[1] == 'open') { echo 'Glowing'; } elseif ($match[1] != 'open') { echo "Not Glowing"; } ?></head> <body> </body> </html> This is my code so far. The output of this is: array(0) { } Not Glowing How do I make it echo just the "Not Glowing", or when the correct data is found on the page I am scraping to say JUST "Glowing", instead of having the arrays showing? Quote Link to comment https://forums.phpfreaks.com/topic/184443-proper-way-to-echo-this-help/ Share on other sites More sharing options...
mrMarcus Posted December 8, 2009 Share Posted December 8, 2009 seriously? just eliminate the line that is displaying the unwanted information: var_dump($match); Quote Link to comment https://forums.phpfreaks.com/topic/184443-proper-way-to-echo-this-help/#findComment-973640 Share on other sites More sharing options...
EsOne Posted December 8, 2009 Author Share Posted December 8, 2009 :'( Sorry, kind of new to PHP. Care to explain exactly what var_dump does? Also, what would be the proper way to loop this (ex. elseif loop until the $match == 'open')? I know I cannot have it constantly looping, but what would be the proper way to make it loop and re-check the data every 5 minutes or so? Quote Link to comment https://forums.phpfreaks.com/topic/184443-proper-way-to-echo-this-help/#findComment-973661 Share on other sites More sharing options...
premiso Posted December 8, 2009 Share Posted December 8, 2009 var_dump. Feel free to consult the manual for function information. As for the loop, look into foreach as that will loop through the array until the array has no more indexes. Quote Link to comment https://forums.phpfreaks.com/topic/184443-proper-way-to-echo-this-help/#findComment-973664 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.