Eiolon Posted February 8, 2012 Share Posted February 8, 2012 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:[email protected]/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! Quote Link to comment https://forums.phpfreaks.com/topic/256683-getting-results-from-http-commands/ Share on other sites More sharing options...
Pikachu2000 Posted February 8, 2012 Share Posted February 8, 2012 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] Quote Link to comment https://forums.phpfreaks.com/topic/256683-getting-results-from-http-commands/#findComment-1315914 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.