Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP PHP Get Webpage Content Using cURL

PHP Get Webpage Content Using cURL

It’s very common task for web developers who want to download remote content of a particular URL, XML, RSS or even call to a API or web service. PHP’s cURL library which often comes with default configuration on popular shared hostings allows us to do that.

Get Web Page Content Function

<?php
function get_webpage_content($webpage_url)
{
	$curl_handle=curl_init();
	curl_setopt($curl_handle,CURLOPT_URL,$webpage_url);
	curl_setopt($curl_handle,CURLOPT_TIMEOUT,10); 
	curl_setopt($curl_handle,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
	curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,10);
	curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
	$html = curl_exec($curl_handle);
	curl_close($curl_handle);
 
	return $html;
}
?>

<?php function get_webpage_content($webpage_url) { $curl_handle=curl_init(); curl_setopt($curl_handle,CURLOPT_URL,$webpage_url); curl_setopt($curl_handle,CURLOPT_TIMEOUT,10); curl_setopt($curl_handle,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,10); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); $html = curl_exec($curl_handle); curl_close($curl_handle); return $html; } ?>

The Usage:

<?php
	echo get_webpage_content("http://4rapiddev.com/php/php-get-webpage-content-using-curl/");
?>

<?php echo get_webpage_content("http://4rapiddev.com/php/php-get-webpage-content-using-curl/"); ?>

Or you can use the file_get_contents:

<?php
	echo file_get_contents("http://4rapiddev.com/php/php-get-webpage-content-using-curl/");
?>

<?php echo file_get_contents("http://4rapiddev.com/php/php-get-webpage-content-using-curl/"); ?>

Feb 24, 2011admin
Letter of resignation ExampleJavascript generate a random number using Math.random
You Might Also Like:
  • How To Track Website With Multiple Google Analytisc Accounts
  • Facebook Like Button And Recommend Button With fb:like, iframe and html5
  • Get Image Width Height With JQuery And JavaScript
  • Jquery checkbox checked
  • Javascript Problem Set focus textbox on Firefox
  • JavaScript Get Radio Button Value
  • PHP CURL Post To HTTPS Website
  • Javascript generate a random number using Math.random
  • PHP Get Remote File Size And Content Type
  • String To Lower Case In PHP, JavaScript And .Net (CSharp)
admin
11 years ago PHPcURL, CURLOPT_CONNECTTIMEOUT, CURLOPT_TIMEOUT, CURLOPT_USERAGENT, file_get_contents, web developers447
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
24,442 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
21,823 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
17,631 views
JQuery Allow only numeric characters or only alphabet characters in textbox
14,978 views
C# Read Json From URL And Parse/Deserialize Json
11,691 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Things to Learn about Installingderm Loan Type S
  • Online Photo Editor – Free Photoediting Software
  • A Guide to Finding the Best Paper Sellers
  • Photoediting in Home Isn’t Hard to Do!

  • Free Photo Editor Online
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (27)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (647)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development