Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-07-2009
Member
 
Join Date: Apr 2008
Posts: 51
php to read xml content from a URL

Hi,

How to tell php to read XML content from a given URL which has XML content?
I know this is possible but I don't have a clear Idea how to do the same?

How will php read xml content from a URL?

Thanks.
Reply With Quote
  #2  
Old 09-07-2009
Member
 
Join Date: Oct 2008
Posts: 115
Re: php to read xml content from a URL

PHP to read XML content from URL:

Once you have the URL of the XML feed that you are going to use, you need to have PHP load the contents of the feed into a string variable. Using file_get_contents, you could fetch the XML file like so:

Code:
$xml = file_get_contents('http://www.dpreview.com/feeds/news.xml');
However, this requires that PHP is setup with allow_url_fopen set to true. Not all web hosts enable this setting, for security reasons. So another way to fetch the XML file into a string is by using the cURL functions (if they are installed on your PHP setup) like this:

Code:
// Use cURL to get the RSS feed into a PHP string variable.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
        'http://www.dpreview.com/feeds/news.xml');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
Reply With Quote
  #3  
Old 09-07-2009
Member
 
Join Date: Apr 2008
Posts: 54
Re: php to read xml content from a URL

Try this:

Code:
<?php
$sxe = simplexml_load_file('article.xml');
print "Output: ".$sxe->name."
";
?>
I hope this is simple.
Reply With Quote
  #4  
Old 09-07-2009
Member
 
Join Date: Oct 2008
Posts: 76
Re: php to read xml content from a URL

Please make sure to check that you have permission to fetch XML content from a URL.
USE
allow_url_fopen boolean

I must say Use CURL instaed of fopen to read the URL.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "php to read xml content from a URL"
Thread Thread Starter Forum Replies Last Post
Content blocker blocks content on certain sites with Opera GiveNTake Technology & Internet 5 21-06-2011 07:30 AM
Can copy and read the new files but cannot read or delete old contents in the hard drive GOOL Hardware Peripherals 3 14-12-2010 04:10 AM
iTunes cannot read iPad content Muses Portable Devices 4 23-04-2010 05:39 AM
READ THIS IF YOU CANNOT GET DRIVE TO READ DISK TO FIX VISTA ERROR! DesTiny! Vista Hardware Devices 2 14-01-2009 02:42 PM


All times are GMT +5.5. The time now is 12:18 PM.