Link to home
Start Free TrialLog in
Avatar of bilbo-uk
bilbo-uk

asked on

parsing external cgi script results to variable in PHP

I want to put the reult of a CGI script into a string, then into an array so i can reformat the results.
I am able to call the external CGI script, which returns the correct result but cant figure out how to get the reults into a string.

The external CGI script is:
http://checker.cerberusnetworks.co.uk/cgi-bin/externaldslcheck.cgi?pstn=01279466222&user=csuk&pass=druney73

The value that is returned is:
ADSL2PLUS_ANNEXA_UP_ESTIMATE=1.25 ADSL2PLUS_ANNEXA_DOWN_ESTIMATE=14.181 ADSL2PLUS_STATUS=0 BT_LINE_LENGTH=1904

does anybody know how to do this?
<?php
$pstn2 = $_POST["pstn"]; 
echo "$pstn2"; 
echo "<br /><br />";
$str = include("http://checker.cerberusnetworks.co.uk/cgi-bin/externaldslcheck.cgi?pstn=01279466222&user=csuk&pass=druney73"); 
echo "<br /><br />";
echo $str;
echo "<br /><br />";
echo $str;
echo "<br /><br />";
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rob Siklos
Rob Siklos
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
eval('$arr=array("'. str_replace(" ",'","',str_replace("=",'"=>"',file_get_contents("http://checker.cerberusnetworks.co.uk/cgi-bin/externaldslcheck.cgi?pstn=01279466222&user=csuk&pass=druney73"))).'");');
print_r($arr);
Avatar of bilbo-uk
bilbo-uk

ASKER

Sorry but the person who posted this has now left the company hence why a comment has not been left earlier.  I don't think it was a complete solution but gave him some things to try which lead to working out how to do it.  

If I can find where the code is I will post what he ended up going with

Thanks

In the end this was done as follows by the look of things

$str = file_get_contents("http://checker.cerberusnetworks.co.uk/cgi-bin/externaldslcheck.cgi?pstn=$pstn2&user=&pass=");
$a = explode(" ", $str);

Then access those array variables

$length = "$a[3]";
$down = "$a[1]";
$status = "$a[2]";
$up = "$a[0]";

Regards

Paul