Results 1 to 4 of 4

Thread: php to read xml content from a URL

  1. #1
    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.

  2. #2
    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);

  3. #3
    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.

  4. #4
    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.

Similar Threads

  1. Content blocker blocks content on certain sites with Opera
    By GiveNTake in forum Technology & Internet
    Replies: 5
    Last Post: 21-06-2011, 07:30 AM
  2. Replies: 3
    Last Post: 14-12-2010, 04:10 AM
  3. iTunes cannot read iPad content
    By Muses in forum Portable Devices
    Replies: 4
    Last Post: 23-04-2010, 05:39 AM
  4. READ THIS IF YOU CANNOT GET DRIVE TO READ DISK TO FIX VISTA ERROR!
    By DesTiny! in forum Vista Hardware Devices
    Replies: 2
    Last Post: 14-01-2009, 02:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,300,836.27448 seconds with 17 queries