Jump to content

Getting results from HTTP commands


Eiolon

Recommended Posts

I have a hardware device that I can send commands to by typing in a URL in the address bar.

 

One command tells me if the ports are in use:

 

http://admin:12345678@192.168.1.10/Set.cmd?CMD=GetPower

 

It returns the result:

 

p61=1,p62=1,p63=1,p64=1 

 

What I want to do is try and grab the result with PHP when the page loads so I can tell people if the port is turned on or off.

 

So "p61=1" means port 1 is turned ON.  If "p61=0" was displayed, it means port 1 is turned OFF.

 

I am not sure if it is even possible to grab the information using PHP or not.  Any place to start would be great!  Thanks!

Link to comment
Share on other sites

Here's one way you could do it. Use file_get_contents to grab the string of values, then explode it on the comma. Further explode each value on the equals sign and assign the port number as an array key, and the value as the value. Then you can access the value via the port number as the array key.

 

$str = 'p61=1,p62=1,p63=1,p64=1,p65=0,p66=0,p67=1'; // assumed to be the result of the call to file_get_contents() . . .
$arr = explode(',', $str);

foreach( $arr as $v ) {
   $tmp = explode('=', $v);
   $ports[$tmp[0]] = (int)$tmp[1];
}

 

var_dump($ports); returns:

 

[pre]array

  'p61' => int 1

  'p62' => int 1

  'p63' => int 1

  'p64' => int 1

  'p65' => int 0

  'p66' => int 0

  'p67' => int 1

[/pre]

Link to comment
Share on other sites

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.