There are situation when you need to fetch data from certain URL. This URL can give you RSS feeds or it can be a JSON data.This tutorial of php code for beginners show you how to read content or data from URL using cURL in php.
<?php
$url = www.phpcodeforbeginner.blogspot.in;
if(isset($url)){
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$html = file_get_contents_curl($url);
//$html contain the whol data from the url specified by you.
}
?>
Now if you want to just read the title of perticular url for your seo perpose then add the below code after $html.
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
//get and display what you need:
$title = $nodes->item(0)->nodeValue;
//Title of url get stored in $title.
Hope this php tutorial is useful for you. Keep following www.phpcodeforbeginner.blogspot.in for more help.
dear sir
ReplyDeletevery -very thanks for hepling this code , this code is working correctly.....
dear i need a tutorial how to get specific page content of html page with php curl function.
ReplyDelete