[ create a new paste ] login | about

Link: http://codepad.org/s4tFbNvM    [ raw code | output | fork ]

PHP, pasted on Mar 30:
<?php

$file = <<<DATAFILE
<?xml version="1.0" encoding="utf-8" ?>
<images>
  <image>
    <startdate>20130330</startdate>
    <fullstartdate>201303300000</fullstartdate>
    <enddate>20130331</enddate>
    <url>/az/hprichbg/rb/BlueButton_EN-US1108621411.jpg</url>
    <urlBase>/az/hprichbg/rb/BlueButton_EN-US10208337365</urlBase>
    <copyright>Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)</copyright>
    <copyrightlink>http://www.bing.com/search?q=Blue+Button+%28Porpita+porpita%29&amp;form=hpcapt</copyrightlink>
    <drk>1</drk>
    <top>1</top>
    <bot>1</bot>
  </image>
  <image>
    <startdate>20130330</startdate>
    <fullstartdate>201303300000</fullstartdate>
    <enddate>20130331</enddate>
    <url>/az/hprichbg/rb/BlueButton_EN-US1108621411.jpg</url>
    <urlBase>/az/hprichbg/rb/BlueButton_EN-US10208337365</urlBase>
    <copyright>Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)</copyright>
    <copyrightlink>http://www.bing.com/search?q=Blue+Button+%28Porpita+porpita%29&amp;form=hpcapt</copyrightlink>
    <drk>1</drk>
    <top>1</top>
    <bot>1</bot>
  </image>
  <image>
    <startdate>20130330</startdate>
    <fullstartdate>201303300000</fullstartdate>
    <enddate>20130331</enddate>
    <url>/az/hprichbg/rb/BlueButton_EN-US1108621411.jpg</url>
    <urlBase>/az/hprichbg/rb/BlueButton_EN-US10208337365</urlBase>
    <copyright>Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)</copyright>
    <copyrightlink>http://www.bing.com/search?q=Blue+Button+%28Porpita+porpita%29&amp;form=hpcapt</copyrightlink>
    <drk>1</drk>
    <top>1</top>
    <bot>1</bot>
  </image>
</images>
DATAFILE;


/*$host = 'http://www.bing.com';
$file = $host . '/HPImageArchive.aspx?format=xml&idx=0&n=10&mkt=en-US';*/
$xml = simplexml_load_string($file);

//var_dump($xml);

foreach ($xml as $image) {
    echo "copyright (object): $image->copyright\n";
    var_dump($image);

    $image = (array) $image;
    echo "copyright (array): {$image['copyright']}\n";
    var_dump($image);
}

?>


Output:
copyright (object): Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)
object(SimpleXMLElement)#3 (10) {
  ["startdate"]=>
  string(8) "20130330"
  ["fullstartdate"]=>
  string(12) "201303300000"
  ["enddate"]=>
  string(8) "20130331"
  ["url"]=>
  string(46) "/az/hprichbg/rb/BlueButton_EN-US1108621411.jpg"
  ["urlBase"]=>
  string(43) "/az/hprichbg/rb/BlueButton_EN-US10208337365"
  ["copyright"]=>
  string(77) "Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)"
  ["copyrightlink"]=>
  string(74) "http://www.bing.com/search?q=Blue+Button+%28Porpita+porpita%29&form=hpcapt"
  ["drk"]=>
  string(1) "1"
  ["top"]=>
  string(1) "1"
  ["bot"]=>
  string(1) "1"
}
copyright (array): Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)
array(10) {
  ["startdate"]=>
  string(8) "20130330"
  ["fullstartdate"]=>
  string(12) "201303300000"
  ["enddate"]=>
  string(8) "20130331"
  ["url"]=>
  string(46) "/az/hprichbg/rb/BlueButton_EN-US1108621411.jpg"
  ["urlBase"]=>
  string(43) "/az/hprichbg/rb/BlueButton_EN-US10208337365"
  ["copyright"]=>
  string(77) "Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)"
  ["copyrightlink"]=>
  string(74) "http://www.bing.com/search?q=Blue+Button+%28Porpita+porpita%29&form=hpcapt"
  ["drk"]=>
  string(1) "1"
  ["top"]=>
  string(1) "1"
  ["bot"]=>
  string(1) "1"
}
copyright (object): Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)
object(SimpleXMLElement)#3 (10) {
  ["startdate"]=>
  string(8) "20130330"
  ["fullstartdate"]=>
  string(12) "201303300000"
  ["enddate"]=>
  string(8) "20130331"
  ["url"]=>
  string(46) "/az/hprichbg/rb/BlueButton_EN-US1108621411.jpg"
  ["urlBase"]=>
  string(43) "/az/hprichbg/rb/BlueButton_EN-US10208337365"
  ["copyright"]=>
  string(77) "Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)"
  ["copyrightlink"]=>
  string(74) "http://www.bing.com/search?q=Blue+Button+%28Porpita+porpita%29&form=hpcapt"
  ["drk"]=>
  string(1) "1"
  ["top"]=>
  string(1) "1"
  ["bot"]=>
  string(1) "1"
}
copyright (array): Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)
array(10) {
  ["startdate"]=>
  string(8) "20130330"
  ["fullstartdate"]=>
  string(12) "201303300000"
  ["enddate"]=>
  string(8) "20130331"
  ["url"]=>
  string(46) "/az/hprichbg/rb/BlueButton_EN-US1108621411.jpg"
  ["urlBase"]=>
  string(43) "/az/hprichbg/rb/BlueButton_EN-US10208337365"
  ["copyright"]=>
  string(77) "Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)"
  ["copyrightlink"]=>
  string(74) "http://www.bing.com/search?q=Blue+Button+%28Porpita+porpita%29&form=hpcapt"
  ["drk"]=>
  string(1) "1"
  ["top"]=>
  string(1) "1"
  ["bot"]=>
  string(1) "1"
}
copyright (object): Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)
object(SimpleXMLElement)#3 (10) {
  ["startdate"]=>
  string(8) "20130330"
  ["fullstartdate"]=>
  string(12) "201303300000"
  ["enddate"]=>
  string(8) "20130331"
  ["url"]=>
  string(46) "/az/hprichbg/rb/BlueButton_EN-US1108621411.jpg"
  ["urlBase"]=>
  string(43) "/az/hprichbg/rb/BlueButton_EN-US10208337365"
  ["copyright"]=>
  string(77) "Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)"
  ["copyrightlink"]=>
  string(74) "http://www.bing.com/search?q=Blue+Button+%28Porpita+porpita%29&form=hpcapt"
  ["drk"]=>
  string(1) "1"
  ["top"]=>
  string(1) "1"
  ["bot"]=>
  string(1) "1"
}
copyright (array): Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)
array(10) {
  ["startdate"]=>
  string(8) "20130330"
  ["fullstartdate"]=>
  string(12) "201303300000"
  ["enddate"]=>
  string(8) "20130331"
  ["url"]=>
  string(46) "/az/hprichbg/rb/BlueButton_EN-US1108621411.jpg"
  ["urlBase"]=>
  string(43) "/az/hprichbg/rb/BlueButton_EN-US10208337365"
  ["copyright"]=>
  string(77) "Blue button near the Cayman Islands, Caribbean (© Lawson Wood/Aurora Photos)"
  ["copyrightlink"]=>
  string(74) "http://www.bing.com/search?q=Blue+Button+%28Porpita+porpita%29&form=hpcapt"
  ["drk"]=>
  string(1) "1"
  ["top"]=>
  string(1) "1"
  ["bot"]=>
  string(1) "1"
}


Create a new paste based on this one


Comments: