Contact Us

Using cURL (Client URLs) with PHP

From time to time PHP web developers need to grab a webpage from somewhere else on the internet to use its contents for some use.

On a shared server system it’s likely that the use of the fopen() or simplexml_load_file() tags for external data is probably prohibited, and for good reason.

However, don’t fear because using PHP’s inbuilt cURL functions, we have a way to fetch this information. cURL, which stands for Client URLs can look complicated at first glance and can be thought of as another subject to learn but in our instance here all we need it for is to fetch a webpage across the World Wide Web and for that it’s not so bad!

Let’s look at a piece of PHP code to fetch a Yahoo RSS feed.

PHP Code

$xml = simplexml_load_file('');


Now this would normally be fine, but not in our shared server where the simplexml_load_file() function is not permitted. Below is aversion of the code above, using cURL to complete the exact same function and can be used in your web development projects easily.



$ch = curl_init("");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($ch);


We now have the information we wanted before but it is saved in our $return variable above. Let’s try and explain a little of what exactly is happening here:

$ch = curl_init(“”);

The curl_init() function initialises our cURL request with the URL of the page we want to fetch.

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

The function above tells cURL that we want the data from the webpage returned and not displayed on our browser.

$return = curl_exec($ch);

Placing the curl_exec() function in it’s own variable, executes the cURL command and then places the return results into our variable $return which we can then manipulate as any other variable using PHP.

This is only the beginning of what cURL can do. Using cURL you can login to remote websites and automate tasks as if it was a real person performing the tasks and much, much more.

If you would like any help using cURL or any other scripting languages or would like help with your own web design or development needs then why not get in contact with us here at Network Intellect.

This article was posted by

Leave a Reply

What our clients say

"It’s like having your own in-house digital marketing consultancy rather than an external company. I no longer think about them as a supplier. They’re part of the team."
Marketing Manager, Education
"They have always been professional and focused on delivering results in a timely and cost effective manner. It is enlightening to have an organisation that takes the time to make recommendations on actual data analysis."
Business Manager, Charity
"They (Network Intellect) continue to exhibit their digital expertise by helping us to establish a competitive advantage by pushing the boundaries and innovating their technology and performance solutions."
Head of Marketing Communications, Education
"Because of their talent, expertise and level of service our on-line business has increased dramatically."
Founder, Electronics
"I would have no hesitation in recommending them as an analytics partner to understand and improve the performance of a website."
Vice President, Retail
Network Intellect continue to give us a fantastic service, fast and friendly and are always ready to go the extra mile. They have gone above and beyond the call of duty to deliver our results.
Director, E-Cigarette Web
"We found that Network Intellect had the depth of knowledge we needed and after speaking to them a few times we decided to go with them. It’s the best decision we’ve made in some time."
Owner, Retail
"Their services offered great value for money. I would not hesitate to recommend them as a digital partner to others."
Strategic Marketing Manager, Education
"Jason and his team at Network Intellect embody efficiency and efficacy. I would have no hesitation in recommending this excellent company to others."
Marketing Manager, Education
Network Intellect have managed our product data feeds with exceptional care and meticulous detail. I know I can trust them to make the right decisions for our business."
Director, E-Commerce
"It’s like having your own in-house digital marketing consultancy rather than an external company. I no longer think about them as a supplier. They’re part of the team."
Marketing Manager, Education
Read all testimonialsRead all testimonials

We can help you be great

We have friendly staff ready to help you get on your path to greatness...
Network Intellect Menu