Tag Archives: cURL

what is cURL in php

cURL is a library that allows PHP applications to communicate with other servers. 

Example :

<?php
$url = “www.example.com”; // Desired URL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$returned = curl_exec($ch);
curl_close ($ch);
echo $returned;
?>

Script to read RSS feed – PHP

<?php
 $connect = curl_init("http://www.unixsite.com/feed/rss/");
 curl_setopt($connect, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($connect, CURLOPT_HEADER, 0) ;
 $result = curl_exec($connect);
 curl_close($connect);
 $data = new SimpleXmlElement($result, LIBXML_NOCDATA);
 for($i=0;$i<10;++$i) {
  if(empty($data->channel->item[$i]->title)) break;
  echo  $data->channel->item[$i]->title; 
  echo  $data->channel->item[$i]->description; 
 }
?>