Jump to content

Proper way to echo this... (Help?)


EsOne

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/184443-proper-way-to-echo-this-help/
Share on other sites

:'(

 

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.