Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Curl and PHP- Need a php script to execute simple get for xml data

Posted on 2006-05-16
2
Medium Priority
?
373 Views
Last Modified: 2010-08-05
I am trying to use PHP to excecute a curl command to get xml data from my root vault,  The documentation for the curl command is here: http://vaults.root.net/api/docs 

Something like this:

download everything ending on a given date:

curl -k -u YOURUSERNAME "https://root.net/people/THEIRUSERNAME/module/dlraw?end=YYYY-MM-DD"

I need the PHP script to excecute this function.  Also I am looking for a way to format my XML data using the DOM module so I can format with css and html etc.
0
Comment
Question by:admin_mjschiff
2 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 16696746
You can use ofcourse the curl_init() etc functions.

An alternative might however be to use:

$xml = file_get_contents('https://username@root.net/people/THEIRUSERNAME/module/dlraw?end=YYYY-MM-DD');

-r-
0
 
LVL 4

Accepted Solution

by:
anilande earned 500 total points
ID: 16740455
try this

function curl_request($url,$request)
{  
      if (function_exists('curl_init')) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            
            $airborne_response = curl_exec($ch);
            curl_close($ch);      
      } else {
            $url=$url."?".$request;
            $fp = fopen($url, "r");
            while(!feof($fp)){
                  $result = fgets($fp, 500);
                  $airborne_response.=$result;
            }
            fclose($fp);
      }  
      return $airborne_response;
}

$xml="some xml request";

//$xml="sdgfdgfd";
$request="xml=".urlencode($xml);
$url="http://profiles.test.peerme.com/xml_parser/index.php";

$response=curl_request($url,$request);
echo $response;exit;
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 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