Getting Results from an url with sending it url variables

i need to send get command and take it's results. Sorry about my bad english. i need to get result from a file whish sended url parameters for example:

<?php

$adata["command1"] = "testcommand1";
$adata["command2"] = "testcommand2";
$getresult = sendGetCommand("https://website.com/api.html", $arrayofdata);

echo "["; // for json data;

$arrayresult = explode("\n",$getresult);
foreach ($getresult in $line) {
  $arrayline = explode("\n",$line);
   echo "{ ";
  foreach ($arrayline in $cmdid => $cmd) {
    echo "'".$cmdid."' : '".$cmd."',";
  }
  echo "{";
}
?>

somethink like this..

url is like: "https://website.com/api.html?command1=testcommand1&command2=testcommand2"

url result is like:


command1,testcommand1,,yes command2,testcommand2,,error,error text here


i'll explode the data line by line and then get the data from JavaScript this is a domain search api.

another question: explode("\n",$string) can be used for read it line by line? (windows os)

Answers


are you talking about file_get_contents? you can create the url with something like:

$url = "https://website.com/api.html?command1=".$adata["command1"]."&command2=".$adata["command2"];
$getresult = file_get_contents($url);

good luck;


for reading the result, you should take a look at str_getcsv and/or fgetcsv instead of doing this by hand using explode.

EDIT: for sending a get-request, you should take a look at fsockopen and its examples. you could use a function like this (just change POST to GET and the content-type like you need it):

function _get($type,$host,$port='80',$path='/',$data='') {
    $_err = 'lib sockets::'.__FUNCTION__.'(): ';
    switch($type) { case 'http': $type = ''; case 'ssl': continue; default: die($_err.'bad $type'); } if(!ctype_digit($port)) die($_err.'bad port');
    if(!empty($data)) foreach($data AS $k => $v) $str .= urlencode($k).'='.urlencode($v).'&'; $str = substr($str,0,-1);

    $fp = fsockopen($host,$port,$errno,$errstr,$timeout=30);
    if(!$fp) die($_err.$errstr.$errno); else {
        fputs($fp, "POST $path HTTP/1.1\r\n");
        fputs($fp, "Host: $host\r\n");
        fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
        fputs($fp, "Content-length: ".strlen($str)."\r\n");
        fputs($fp, "Connection: close\r\n\r\n");
        fputs($fp, $str."\r\n\r\n");

        while(!feof($fp)) $d .= fgets($fp,4096);
        fclose($fp);
    } return $d;
} 

Need Your Help

SQL new column with pattern match

sql tsql pattern-matching design-patterns substr

I have a column with a url sting that looks like this

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.