I am trying to get the attachment url in $getAttachmentURL so it is possible to download the file. I get the error code 1006 - not found.
<?php
$baseURL = "https://api.smartsheet.com/1.1";
$sheetsURL = $baseURL."/sheets/";
$getSheetURL = $baseURL."/sheet/3712544801089412";
$rowsURL = $baseURL."/sheet/3712544801089412/rows";
$rowAttachmentsURL = $baseURL."/sheet/3712544801089412/row/{{ROWID}}/attachments";
$getAttachmentURL = $baseURL."/sheet/3712544801089412/attachment/{{ATTACHMENTID}}";
// Insert your Smartsheet API Token here
$accessToken = "xxx";
// Create Headers Array for Curl
$header = array(
"Authorization: Bearer ".$accessToken,
"Content-Type: application/json"
);
// Connect to Smartsheet API to get Selected Sheet
$curlSession = curl_init($getSheetURL);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $header);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
$getSheetResponseData = curl_exec($curlSession);
$sheetObj = json_decode($getSheetResponseData);
echo "<h1>Sheet name: ".$sheetObj->name."</h1>";
echo "<br>";
//table start
echo "<table>";
echo "<td>"."Attachment"."</td>";
foreach($sheetObj->columns as $column) {
echo "<td>".$column->title."</td>";
}
echo "<tr>";
foreach($sheetObj->rows as $row) {
$rowAttachmentsURL = str_replace('3712544801089412', $row->id, $rowAttachmentsURL);
$chosenRow = $row->id;
$rowAttachmentsURL = $baseURL."/sheet/3712544801089412/row/$chosenRow/attachments";
$rowAttachmentsURL = str_replace($chosenRow, $row->id, $rowAttachmentsURL);
$curlSession = curl_init($rowAttachmentsURL);
$rowsResponse = curl_exec($curlSession);
// Assign response to variable
$addRowsObj = json_decode($rowsResponse);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, $header);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
$getAttachmentsResponse = curl_exec($curlSession);
// Assign response to variable
$attachment = json_decode($getAttachmentsResponse);
$rowAttachTags = array($chosenRow->id, $theSheet->id, $attachments[0]->id);
$rowAttachVals = array($addRowsObj->result[0]->id, $theSheet->id, $attachments[0]->id);
$getAttachmentURL = str_replace($rowAttachTags, $rowAttachVals, $getAttachmentURL);
$type = $attachment[0]->mimeType;
$size = $attachment[0]->sizeInKb;
$filename = $attachment[0]->name;
// Print headers
header("Content-Type: $type");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename=$filename");
echo "<td><a href='".$getAttachmentURL."'>".$attachment[0]->name."</a></td>";
//echo "<td>".$attachment[0]->id."</td>";
foreach($row->cells as $cell) {
echo "<td>".$cell->value."</td>";
}
echo "<td></td><td></td><td></td>";
echo "</tr>";
}
echo "</table>";
I am a little confused abort it all so i really need your help
The row attachments url should be rows not row
Yours:
$rowAttachmentsURL = $baseURL."/sheet/3712544801089412/row/{{ROWID}}/attachments";
Correct:
$rowAttachmentsURL = $baseURL."/sheet/3712544801089412/rows/{{ROWID}}/attachments";
Related
I have been working on a clients WP site which lists deals from Groupon. I am using the Groupon's official XML feed, importing via WP All Import. This works without much hassle. Now the issue is Groupon doesn't update that feed frequently but some of their deals get sold out or off the market often. So to get this resolved what I am trying is using a CURL script to crawl the links and check if the deal is available or not then turn the unavailable deals to draft posts (Once a day only).
The custom script is working almost perfectly, only after the first 14/24 requests the server starts responding with 502/503 HTTP status codes. To overcome the issue I have used the below precautions -
Using the proper header (captured from the requests made by the browser)
Parsing cookies from response header and sending back.
Using proper referrer and user agent.
Using proxies.
Trying to send request after a set interval. PHP - sleep(5);
Unfortunately, none of this got me the solution I wanted. I am attaching my code and I would like to request your expert insights on the issue, please.
Thanks in advance for your time.
Shahriar
PHP SCRIPT - https://pastebin.com/FF2cNm5q
<?php
// Error supressing and extend maximum execution time
error_reporting(0);
ini_set('max_execution_time', 50000);
// Sitemap URL List
$all_activity_urls = array();
$sitemap_url = array(
'https://www.groupon.de/sitemaps/deals-local0.xml.gz'
);
$cookies = Array();
// looping through sitemap url for scraping activity urls
for ($u = 0; $u < count($sitemap_url); $u++)
{
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0');
curl_setopt($ch1, CURLOPT_REFERER, "https://www.groupon.de/");
curl_setopt($ch1, CURLOPT_TIMEOUT, 40);
// curl_setopt($ch1, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_URL, $sitemap_url[$u]);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, FALSE);
// Parsing Cookie from the response header
curl_setopt($ch1, CURLOPT_HEADERFUNCTION, "curlResponseHeaderCallback");
$activity_url_source = curl_exec($ch1);
$status_code = curl_getinfo($ch1, CURLINFO_HTTP_CODE);
curl_close($ch1);
if ($status_code === 200)
{
// Parsing XML sitemap for activity urls
$activity_url_list = json_decode(json_encode(simplexml_load_string($activity_url_source)));
for ($a = 0; $a < count($activity_url_list->url); $a++)
{
array_push($all_activity_urls, $activity_url_list->url[$a]->loc);
}
}
}
if (count($all_activity_urls) > 0)
{
// URL Loop count
$loop_from = 0;
$loop_to = (count($all_activity_urls) > 0) ? 100 : 0;
// $loop_to = count($all_activity_urls);
$final_data = array();
echo 'script start - ' . date('h:i:s') . "<br>";
for ($u = $loop_from; $u < $loop_to; $u++)
{
//Pull source from webpage
$headers = array(
'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'accept-language: en-US,en;q=0.9,bn-BD;q=0.8,bn;q=0.7,it;q=0.6',
'cache-control: max-age=0',
'cookie: ' . implode('; ', $cookies),
'upgrade-insecure-requests: 1',
'user-agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
);
$site = $all_activity_urls[$u];
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, "https://www.groupon.de/");
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $site);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// Parsing Cookie from the response header
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "curlResponseHeaderCallback");
$data = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status_code === 200)
{
// Ready data for parsing
$document = new DOMDocument();
$document->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">' . $data);
$xpath = new DOMXpath($document);
$title = '';
$availability = '';
$price = '';
$base_price = '';
$link = '';
$image = '';
$link = $all_activity_urls[$u];
// Scraping Availability
$raw_availability = $xpath->query('//div[#data-bhw="DealHighlights"]/div[0]/div/div');
$availability = $raw_availability->item(0)->nodeValue;
// Scraping Title
$raw_title = $xpath->query('//h1[#id="deal-title"]');
$title = $raw_title->item(0)->nodeValue;
// Scraping Price
$raw_price = $xpath->query('//div[#class="price-discount-wrapper"]');
$price = trim(str_replace(array("$", "€", "US", " "), array("", "", "", ""), $raw_price->item(0)->nodeValue));
// Scraping Old Price
$raw_base_price = $xpath->query('//div[contains(#class, "value-source-wrapper")]');
$base_price = trim(str_replace(array("$", "€", "US", " "), array("", "", "", ""), $raw_base_price->item(0)->nodeValue));
// Creating Final Data Array
array_push($final_data, array(
'link' => $link,
'availability' => $availability,
'name' => $title,
'price' => $price,
'baseprice' => $base_price,
'img' => $image,
));
}
else
{
$link = $all_activity_urls[$u];
if ($status_code === 429)
{
$status_msg = ' - Too Many Requests';
}
else
{
$status_msg = '';
}
array_push($final_data, array(
'link' => $link,
'status' => $status_code . $status_msg,
));
}
echo 'before break - ' . date('h:i:s') . "<br>";
sleep(5);
echo 'after break - ' . date('h:i:s') . "<br>";
flush();
}
echo 'script end - ' . date('h:i:s') . "<br>";
// Converting data to XML
$activities = new SimpleXMLElement("<?xml version=\"1.0\"?><activities></activities>");
array_to_xml($final_data, $activities);
$xml_file = $activities->asXML('activities.xml');
if ($xml_file)
{
echo 'XML file have been generated successfully.';
}
else
{
echo 'XML file generation error.';
}
}
else
{
$activities = new SimpleXMLElement("<?xml version=\"1.0\"?><activities></activities>");
$activities->addChild("error", htmlspecialchars("No URL scraped from sitemap. Stoping script."));
$xml_file = $activities->asXML('activities.xml');
if ($xml_file)
{
echo 'XML file have been generated successfully.';
}
else
{
echo 'XML file generation error.';
}
}
// Recursive Function for creating XML Nodes
function array_to_xml($array, &$activities)
{
foreach ($array as $key => $value)
{
if (is_array($value))
{
if (!is_numeric($key))
{
$subnode = $activities->addChild("$key");
array_to_xml($value, $subnode);
}
else
{
$subnode = $activities->addChild("activity");
array_to_xml($value, $subnode);
}
}
else
{
$activities->addChild("$key", htmlspecialchars("$value"));
}
}
}
// Cookie Parsing Function
function curlResponseHeaderCallback($ch, $headerLine)
{
global $cookies;
if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1)
{
$cookies[] = $cookie[1];
}
return strlen($headerLine); // Needed by curl
}
There is a mess of cookies in your snippet. The callback function just appends cookies to the array regardingless of whether they already exist or not. Here is a new version which at least seems to work in this case since there are no semicolon-seperated multiple cookie definitions. Usually the cookie string should be even parsed. If you have installed the http extension you can use http_parse_cookie.
// Cookie Parsing Function
function curlResponseHeaderCallback($ch, $headerLine)
{
global $cookies;
if (preg_match('/^Set-Cookie:\s*([^;]+)/mi', $headerLine, $match) == 1)
{
if(false !== ($p = strpos($match[1], '=')))
{
$replaced = false;
$cname = substr($match[1], 0, $p+1);
foreach ($cookies as &$cookie)
if(0 === strpos($cookie, $cname))
{
$cookie = $match[1];
$replaced = true;
break;
}
if(!$replaced)
$cookies[] = $match[1];
}
var_dump($cookies);
}
return strlen($headerLine); // Needed by curl
}
I am trying to get the data of any website in my .txt file using curl in php.
so there is some issue in code. yesterday i get the data in web_content.txt file. But i don not know why and where error generate i am not getting the site url in .txt file.
Here is my code you can check and please help me what should i do to remove this error and get the data.
<?php
if($_REQUEST['url_text'] == "") {
echo "<div class='main_div border_radius'><div class='sub_div'> Please type any site URL.</div></div>";
} else {
$site_url = $_REQUEST['url_text'];
$curl_ref=curl_init();//init the curl
curl_setopt($curl_ref,CURLOPT_URL,$site_url);// Getting site
curl_setopt($curl_ref,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_ref,CURLOPT_RETURNTRANSFER,true);
$site_data = curl_exec($curl_ref);
if (empty($site_data)) {
echo "<div class='main_div border_radius'><div class='sub_div'> Data is not available.</div></div>";
}
else {
echo "<div class='main_div border_radius'><div class='sub_div'>".$site_data."</div></div>";
}
$fp = fopen("web_content.txt", "w") or die("Unable to open file!");//Open a file in write mode
curl_setopt($curl_ref, CURLOPT_FILE, $fp);
curl_setopt($curl_ref, CURLOPT_HEADER, 0);
curl_exec($curl_ref);
curl_close($curl_ref);
fclose($fp);
}
?>
if(isset($_GET['start_tag_textbox']) && ($_GET['end_tag_textbox'])) {
get_tag_data($_GET['start_tag_textbox'],$_GET['end_tag_textbox']);
}
header('content-type: text/plain');
function get_tag_data ($start,$end) {
$file_data= "";
$tag_data = "";
$file = fopen("web_content.txt","r");
$file_data = fread($file,filesize("web_content.txt"));
fclose($file);
$last_pos = strpos($start,'>');
$start = substr_replace($start,".*>",$last_pos);
preg_match_all('#'.$start.'(.*)'.$end.'#U',$file_data,$matches);
for($i=0; $i<count($matches[1]);$i++){
echo $matches[1][$i]."\n";
}
}
?>
<?php
$url = "http://www.ucertify.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
$file = fopen("web_content.txt","w");
fwrite($file,$output);
fclose($file);
?>
recently i upgraded my VPS server so as to increase the ram and storage
After upgrade i noticed that my payment api started giving an error
Error: Illegal characters found in URL
Which i have never encountered before, my API which is used for processing
payments has been running for years and just stopped in march after my upgraded
This is the code am using presently
<?php
/* $myparams = array();
$myparams['subpdtid'] = #### ;
$myparams['submittedref'] = $_SESSION['genref'] ;
$myparams['submittedamt'] = $_SESSION['amt4hash'] ;
$myparams['rettxref'] = $_POST['txnref'] ;
$myparams['retpayRef'] = $_POST['payRef'] ;
$myparams['retretref'] = $_POST['retRef'] ;
$myparams['retcardnum'] = $_POST['cardNum'] ;
$myparams['retappramt'] = $_POST['apprAmt'] ;
$myparams['nhash'] = '########################################################################' ;
*/
$subpdtid = ####; // your product ID
$submittedref = $_POST['tnx_ref']; // unique ref I generated for the trans
$submittedamt = $_POST['amount'];
//$rettxref= $_POST['txnref']; // ref from isw
//$retpayRef=$_POST['payRef']; // pay ref from isw
//$retretref = $_POST['retRef']; // ret ref from isw
//$retcardnum = $_POST['cardNum']; // ret cardnum from isw
//$retappramt = $_POST['apprAmt']; // ret appr amt from isw
$nhash = "04F61D7F7EEE6C80E5D227CA6DAAEA878F46C47B67A9DC7A5A699AD2D13A6249187E85667709F0D978D6697E33817DC771FBA109110ADAD1C4E642D20D439BC2" ; // the mac key sent to you
$hashv = $subpdtid.$submittedref.$nhash; // concatenate the strings for hash again
$thash = hash('sha512',$hashv);
// $credentials = "mithun:mithun";
$parami = array(
"productid"=>$subpdtid,
"transactionreference"=>$submittedref,
"amount"=>$submittedamt
);
$ponmo = http_build_query($parami) . "\n";
//$url = "https://stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.xml?$ponmo";// xml
$url = "https://webpay.interswitchng.com/paydirect/api/v1/gettransaction.json?$ponmo"; // json
//note the variables appended to the url as get values for these parameters
$headers = array(
"GET /HTTP/1.1",
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1",
//"Content-type: multipart/form-data",
//"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language: en-us,en;q=0.5",
//"Accept-Encoding: gzip,deflate",
//"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
"Keep-Alive: 300",
"Connection: keep-alive",
//"Hash:$thash",
"Hash: $thash " );
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,120);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER ,false);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$data = curl_exec($ch);
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
}
else {
// Show me the result
// $json = simplexml_load_string($data);
$json = json_decode($data, TRUE);
//var_dump($data);
curl_close($ch);
print_r($json);
//echo ($json['ResponseCode']);
//echo ($json['ResponseDescription']);
// loop through the array nicely for your UI
}?>
<?php session_start();
//if(isset($_POST['name'])){
//$amt1 = htmlspecialchars(mysql_real_escape_string($_POST['amount'])) * 100 ;
$desc = $json['ResponseDescription'];
$_SESSION['desc'] = $desc;
$rep = $json['ResponseCode'];
$_SESSION['rep'] = $rep;
$tref = $_POST['tnx_ref'];
$_SESSION['tref'] = $tref;
$amts = $_POST['amount'] /100;
$_SESSION['amount'] = $amts;
//}
?>
<?php echo ($json['ResponseCode']); ?>
<?php echo ($json ->ResponseDescription);?><div align ="center"><h2 style="color:#090" align="center"> <?php echo ($json['ResponseDescription'] ); ?> </h2><br /><img src="wait.gif" width="200" /><div align ="center"><form action="query.php" method="post" name="niid" id="niid"></form><br /></div>
<script type="text/javascript">
window.onload=function(){
window.setTimeout(function() { document.niid.submit(); }, 3000);
};
</script>
<?php } else {?>
<div align ="center"><h2 style="color:#F00" align="center"> Your Transaction Was Not Successfull<br />Reason: <?php echo ($json['ResponseDescription'] ); ?></h2><br /><img src="wait.gif" width="200" /></div>
Please can anyone enlighten me?
It is because you are appending unwanted \n after string
change your code to
$ponmo = http_build_query($parami);
//$url = "https://stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.xml?$ponmo";// xml
$url = "https://webpay.interswitchng.com/paydirect/api/v1/gettransaction.json?$ponmo"; // json
I have written a function in PHP to send a CURl request.
The code is given below.
function curl_post($url,$fields,$headers=[],$connect_timeout = 3,$timeout = 20) {
$ch = curl_init();
$postvars = '';
foreach($fields as $key=>$value) {
$postvars .= $key . "=" . $value . "&";
}
$postvars = trim($postvars,'&');
$postvars = json_encode($fields);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST, 1); //0 for a get request
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,$connect_timeout);
curl_setopt($ch,$timeout, 20);
$refined_headers = [];
if(sizeof($headers)) {
foreach($headers as $name => $value) {
$refined_headers[] = "'".$name.": ".$value."'";
}
print_r($refined_headers);
//$refined_headers = ['Content-Type: application/json'];
//echo $refined_headers;exit;
curl_setopt($ch,CURLOPT_HTTPHEADER,$refined_headers);
}
$response = curl_exec($ch);
$info = curl_getinfo($ch,CURLINFO_CONTENT_TYPE);
print_r($info);
curl_close ($ch);
return $response;
}
So I called the function like this
$url = API_ENDPOINT.$method.'/';
$response = curl_post($url,$params_to_send,$headers);
echo $response;
where $url contains my API url and $params contain the parameters as associative array and $headers as follows
$headers = ['Content-Type'=>'application/json'];
My problem is that, the content type header is setting. But when I manually set it inside the curl_post function like
$refined_headers = ['Content-Type: application/json']
it is working perfectly.
What is the problem with my code.
Fixed the issue. The problem was
I put two single quotes before and after the header, which was not needed
$refined_headers[] = "'".$name.": ".$value."'";
I changed that to the following and the issueis resolved.
$refined_headers[] = $name.": ".$value;
i want to parse a website but
i always get an Error: service out of order.
No matter what start or end string i give.
I also tried to use an other URL and i copied
full examples from other users that works for them
but not for me. I also tried to increase the Size to 20000.
But nothing is working.
Here is my php-Script:
<?php
// URL, die durchsucht werden soll
$url = "http://cordis.europa.eu/project/rcn/85400_en.html";
// Zeichenfolge vor relevanten Einträgen
$startstring = "<div class='tech'><p>";
// bis zum nächsten html tag bzw. Zeichenfolge nach relevanten Einträgen
$endstring = "<";
$file = #fopen ($url,"r");
if($file)
{
echo "URL found<br>";
}
if (trim($file) == "") {
echo "Service out of order - File:".$file."<br>";
} else {
$i=0;
while (!feof($file)) {
// Wenn das File entsprechend groß ist, kann es unter Umständen
// notwendig sein, die Zahl 2000 entsprechend zu erhöhen. Im Falle
// eines Buffer-Overflows gibt PHP eine entsprechende Fehlermeldung aus.
$zeile[$i] = fgets($file,20000);
$i++;
}
fclose($file);
}
// Data filtering
for ($j=0;$j<$i;$j++) {
if ($resa = strstr($zeile[$j],$startstring)) {
$resb = str_replace($startstring, "", $resa);
$endstueck = strstr($resb, $endstring);
$resultat .= str_replace($endstueck,"",$resb);
$resultat .= "; ";
}
}
// Data output
echo ("Result = ".$resultat."<br>");
return $resultat;
Any help is appreciate.
thanks in advance
EDIT: The URL is found and file has a value: Resource id #3
Try
<?php
// URL, die durchsucht werden soll
$url = "http://cordis.europa.eu/project/rcn/85400_en.html";
$html = file_get_contents($url);
if ($html === false) {
//Service unavailable
echo 'Service unavailable';
return;
}
$dom = new DOMDocument;
$dom->loadHTML($html);
$xpath = new DomXpath($dom);
$div = $xpath->query("//*[#class='tech']")->item(0);
$output = trim($div->textContent);
// Data output
echo ("Result = " . $output. "<br>");
return $output;
Use this it will give expected output.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://cordis.europa.eu/project/rcn/85400_en.html");
curl_setopt($ch, CURLOPT_GET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, '');
$headers = array();
$headers[] = 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
$headers[] = 'Accept-Encoding:gzip, deflate, sdch';
$headers[] = 'Accept-Language:en-US,en;q=0.8';
$headers[] = 'Cache-Control:max-age=0';
$headers[] = 'Connection:keep-alive';
$headers[] = 'Cookie:CORDIS=14.141.177.158.1441621012200552; PHPSESSID=jrf2e3t4vu56acdkf9np0tat06; WT_FPC=id=14.141.177.158-1441621016.978424:lv=1441605951963:ss=1441604805004
Host:cordis.europa.eu';
$headers[] = 'User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36';
$headers[] = 'Host:cordis.europa.eu';
$headers[] = 'Request URL:http://cordis.europa.eu/project/rcn/85400_en.html';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument;
$dom->loadHTML($server_output);
$xpath = new DomXpath($dom);
$div = $xpath->query("//*[#class='tech']")->item(0);
$data = trim($div->textContent);
echo $data;
?>
Output