danIT Posted April 14, 2009 Posted April 14, 2009 If you have ever seen a post from me in the coding forum you will know that programming isnt exactly my strong point so I appreciate any reply...... if (isset($_GET['tag'])) { echo 'download.png '; for($page = 1; $page <= $max_pages; $page++) { $url = "http://search.twitter.com/search.atom?lang=en&q={$tag}&rpp=100&page={$page}"; $xmlstr = file_get_contents($url); $xml = new SimpleXMLElement($xmlstr); foreach ($xml->entry as $entry) { foreach ($entry->link as $link) { switch((string) $link['rel']) { // Get attributes as element indices case 'image': $dp = $link['href']; break; } } echo ' '.$dp.' '.$entry->updated.' '.$entry->author->name.': '.$entry->content.' '; flush(); } } } else { echo 'You are limited by only being able to download a maximum of 5000 tweets. Follow me: @moodledan'; } ?> Had some help from JackD in putting this together but ill draw your attention to the line: '.$entry->updated.' This outputs: 2009-04-14T17:37:35Z Id like it to output: 14-04-2009 17:37:35 Removing the T and Z and re-organising the layout. Now im guessing its not all possible in one simple "one liner" but if somone could: A: Tell me where in the code to put the relevant regex I was thinking somewhere here: foreach ($entry->link as $link) { switch((string) $link['rel']) { // Get attributes as element indices case 'image': $dp = $link['href']; break; } B: Which regex/bit of code do i need to enable me to remove the Z and T C: Re-arrange the date? Dan
dhicks Posted April 14, 2009 Posted April 14, 2009 '.$entry->updated.' Could you just use string split?: '.split("T",$entry->updated)[0].' '.split("Z",split("T",$entry->updated)[1])[0]' -- David Hicks
danIT Posted April 14, 2009 Author Posted April 14, 2009 Thanks Dhicks but I get the following error: unexpected ] was expecting ' or ; Can you help?
powdarrmonkey Posted April 14, 2009 Posted April 14, 2009 Don't bother with a regex, PHP can do this natively in two steps: $ds = "2009-04-14T17:37:35Z"; // this is the string you already have $dt = strtotime($ds); // the strtotime() function takes a string in standard-ish form and tries to turn it into a UNIX timestamp, like 1239730655 in this case echo $dt."\n"; echo date("d-m-Y H:i", $dt)."\n"; //date() formats a UNIX timestamp back into human-readable, according to specification (the first parameter) References: PHP: strtotime - Manual, PHP: date - Manual 1
danIT Posted April 15, 2009 Author Posted April 15, 2009 Worked like a charm, and clearly a much more sensible solution.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now