<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1044906" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1044906</link>
    <description></description>
    <language>en</language>
          <item>
    <title>pr0gr4mm3r wrote:
Welcome to</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/beginners-question-php-simplexml#comment-1244992</link>
    <description> &lt;p&gt;&lt;div class=&quot;quote-msg&quot;&gt;&lt;div class=&quot;quote-author&quot;&gt;&lt;em&gt;pr0gr4mm3r&lt;/em&gt; wrote:&lt;/div&gt;Welcome to the forums, jbudd!  Try something like this...&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;/* fetchs the XML from a local file */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$data &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;file_get_contents&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;data.xml&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;/* parse the XML into a PHP object */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$xml &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= new &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;SimpleXMLElement&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Just curious, what is the advantage of using the above as opposed to just using:&lt;/p&gt;
&lt;p&gt;$xml = simplexml_load_file($xmlfeed);&lt;/p&gt;
&lt;p&gt;I&#039;m still trying to get my head around using PHP for XML.&lt;/p&gt;
 </description>
     <pubDate>Sun, 20 Sep 2009 02:27:34 +0000</pubDate>
 <dc:creator>Renegade</dc:creator>
 <guid isPermaLink="false">comment 1244992 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>DOH!  I should have known</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/beginners-question-php-simplexml#comment-1244939</link>
    <description> &lt;p&gt;DOH!  I should have known that there would be multiple events on the same day.  Good catch &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Wed, 16 Sep 2009 14:19:13 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1244939 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Ahah! ksort() works.
I&#039;ll</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/beginners-question-php-simplexml#comment-1244938</link>
    <description> &lt;p&gt;Ahah! ksort() works.&lt;/p&gt;
&lt;p&gt;I&#039;ll make a php programmer yet!&lt;/p&gt;
&lt;p&gt;Thanks for the help.&lt;br /&gt;
jb&lt;/p&gt;
 </description>
     <pubDate>Wed, 16 Sep 2009 13:52:10 +0000</pubDate>
 <dc:creator>jbudd</dc:creator>
 <guid isPermaLink="false">comment 1244938 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>ps this is the feed used in</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/beginners-question-php-simplexml#comment-1244937</link>
    <description> &lt;p&gt;ps this is the feed used in the above example&lt;br /&gt;
&lt;a href=&quot;http://www.wcwg.info/feeds/localevents.aspx?a=00389&amp;amp;f=20090916&amp;amp;t=20091016&amp;amp;p=ST21 9JU&amp;amp;d=20&amp;amp;c=0011111111111111111&amp;amp;r=0&amp;amp;m=5&quot;&gt;http://www.wcwg.info/feeds/localevents.aspx?a=00389&amp;amp;f=20090916&amp;amp;t=20091016&amp;amp;p=ST21 9JU&amp;amp;d=20&amp;amp;c=0011111111111111111&amp;amp;r=0&amp;amp;m=5&lt;/a&gt;&lt;/p&gt;
 </description>
     <pubDate>Wed, 16 Sep 2009 13:47:38 +0000</pubDate>
 <dc:creator>jbudd</dc:creator>
 <guid isPermaLink="false">comment 1244937 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Thanks for the reply 
I</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/beginners-question-php-simplexml#comment-1244936</link>
    <description> &lt;p&gt;Thanks for the reply &lt;/p&gt;
&lt;p&gt;I have/had a couple of problems. First was multiple events on the same day so the array ends up with less elements. To fix it I added a record count to the time (which ends 00 for all these dates)&lt;/p&gt;
&lt;p&gt;Second, the sort() does something, but it doesnt sort by the time.&lt;/p&gt;
&lt;p&gt;Here is my debug code before sort()&lt;br /&gt;
Event 299587 Dates 19 Sep 09 Time: 1253314800 Formatted: Sat, 19 Sep 2009 00:00:00 +0100&lt;br /&gt;
Event 299590 Dates 10 Oct 09 Time: 1255129201 Formatted: Sat, 10 Oct 2009 00:00:01 +0100&lt;br /&gt;
Event 291193 Dates 10 Oct 09 Time: 1255129202 Formatted: Sat, 10 Oct 2009 00:00:02 +0100&lt;br /&gt;
Event 291827 Dates 18 Sep 09 to 19 Sep 09 Time: 1253228403 Formatted: Fri, 18 Sep 2009 00:00:03 +0100&lt;br /&gt;
Event 295999 Dates 19 Sep 09 to 20 Sep 09 Time: 1253314804 Formatted: Sat, 19 Sep 2009 00:00:04 +0100 &lt;/p&gt;
&lt;p&gt;and here it is after sort()&lt;br /&gt;
Event 295999 Dates 19 Sep 09 to 20 Sep 09 Time 0&lt;br /&gt;
Event 291827 Dates 18 Sep 09 to 19 Sep 09 Time 1&lt;br /&gt;
Event 291193 Dates 10 Oct 09 Time 2&lt;br /&gt;
Event 299590 Dates 10 Oct 09 Time 3&lt;br /&gt;
Event 299587 Dates 19 Sep 09 Time 4&lt;/p&gt;
&lt;p&gt;They are not coming out in date order!&lt;/p&gt;
&lt;p&gt;I tried asort() too. It retains the key, but the sort order is the same&lt;br /&gt;
Event 295999 Dates 19 Sep 09 to 20 Sep 09 Time 1253314804&lt;br /&gt;
Event 291827 Dates 18 Sep 09 to 19 Sep 09 Time 1253228403&lt;br /&gt;
Event 291193 Dates 10 Oct 09 Time 1255129202&lt;br /&gt;
Event 299590 Dates 10 Oct 09 Time 1255129201&lt;br /&gt;
Event 299587 Dates 19 Sep 09 Time 1253314800&lt;/p&gt;
 </description>
     <pubDate>Wed, 16 Sep 2009 13:42:52 +0000</pubDate>
 <dc:creator>jbudd</dc:creator>
 <guid isPermaLink="false">comment 1244936 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>Welcome to the forums,</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/beginners-question-php-simplexml#comment-1244935</link>
    <description> &lt;p&gt;Welcome to the forums, jbudd!  Try something like this...&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;/* fetchs the XML from a local file */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$data &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;file_get_contents&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;data.xml&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;/* parse the XML into a PHP object */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$xml &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= new &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;SimpleXMLElement&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;/* loop through all the items in the feed */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$items &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= array();&lt;br /&gt;foreach (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$xml&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;item &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;as &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$field &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$item&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;/* grab the first date and process it into a timestamp */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;strpos&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$item&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;Dates&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039; to &#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) !== &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$date &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;explode&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039; to &#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$item&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;Dates&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$time &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;strtotime&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$date&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;/* if there is only one date, no need to split it up */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$time &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;strtotime&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$item&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;Dates&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;/* for debugging purposes&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo &#039;Original: &#039; . $item-&amp;gt;Dates . &quot;\n&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo &#039;Time: &#039; . $time . &quot;\n&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; echo &#039;Formatted: &#039; . date(&#039;r&#039;, $time) . &quot;\n&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* add the item to a new array, with the timestamp as the key, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; so we can sort it later */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$items&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$time&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$item&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;sort&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$items&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;/* see what we got */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;header&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;Content-type: text/plain&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$items&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;I&#039;m basically getting the start date, and converting it to a timestamp.  Then form a new array of items, with that the timestamps as the keys, and sort.&lt;/p&gt;
&lt;p&gt;If you want to run the example, make sure to save your XML data in the above mentioned XML file.&lt;/p&gt;
 </description>
     <pubDate>Wed, 16 Sep 2009 11:38:22 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1244935 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>well first I do this $xml =</title>
    <link>https://www.webmaster-forums.net/web-programming-and-application-development/beginners-question-php-simplexml#comment-1244922</link>
    <description> &lt;p&gt;well first I do this &lt;code&gt;$xml = simplexml_load_file($xmlfeed);&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;and I suspect I need to insert a new attribute unixtime to sort with?&lt;/p&gt;
&lt;p&gt;something like&lt;br /&gt;
&lt;code&gt;$xml-&amp;gt;item[something]-&amp;gt;addAttribute(&amp;quot;unixtime&amp;quot;, strtotime(preg_replace(&amp;#039;/to.*/&amp;#039;,&amp;#039;&amp;#039;,$xml-&amp;gt;item[something][&amp;quot;Dates&amp;quot;])));&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I dont know how to add that to each item though.&lt;/p&gt;
 </description>
     <pubDate>Tue, 15 Sep 2009 23:57:02 +0000</pubDate>
 <dc:creator>jbudd</dc:creator>
 <guid isPermaLink="false">comment 1244922 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
