[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

parsing external cgi script results to variable in PHP

Posted on 2009-02-17
5
Medium Priority
?
315 Views
Last Modified: 2013-12-25
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
Comment
Question by:bilbo-uk
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
Rob Siklos earned 1500 total points
ID: 23659983
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 23703948
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
 

Author Comment

by:bilbo-uk
ID: 23792831
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
 

Author Closing Comment

by:bilbo-uk
ID: 31547749
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
The viewer will learn how to dynamically set the form action using jQuery.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month18 days, 3 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question