• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

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

0
bilbo-uk
Asked:
bilbo-uk
  • 2
1 Solution
 
Rob SiklosCommented:
try this:
$url = urlencode("http://checker.cerberusnetworks.co.uk/cgi-bin/externaldslcheck.cgi?pstn=01279466222&user=csuk&pass=druney73");
 
$str = file_get_contents($url); 

Open in new window

0
 
ahoffmannCommented:
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);
0
 
bilbo-ukAuthor Commented:
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

0
 
bilbo-ukAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now