+ Post New Thread
Results 1 to 5 of 5
Coding Thread, Regular Expression (I think) in Coding and Web Development; If you have ever seen a post from me in the coding forum you will know that programming isnt exactly ...
  1. #1

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29

    Regular Expression (I think)

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

    Code:
    <?php
    if (isset($_GET['tag']))
    {
     echo '<div class="download"><a href="twitter_csv.php?tag='.$tag.'&maxpages='.$max_pages.'"><img src="download.png" /></a></div><br><div class="scroll">';
    	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 '<div class="tweetScroller">
    					<div class="tweet">
    					<div class="userImage">
    					<a href="'.$entry->author->uri.'"><img src="'.$dp.'" alt="'.$entry->author->name.'" title="'.$entry->author->name.'" width="48px" height="48px" /></a>
    					</div>
    					<div class="date">'.$entry->updated.'</div>
    					<div class="content">
    					<a href=""><span class="username">'.$entry->author->name.'</span></a>: 
    					'.$entry->content.'
    					</div>
    				</div>
    				</div>';
    				flush();
    			}
    	}
    }
    else
    {
    
    echo '<div id="about">You are limited by only being able to download a maximum of 5000 tweets. <br><br> Follow me: @moodledan</div>';
    }
    
    
    ?>
    Had some help from JackD in putting this together but ill draw your attention to the line:

    Code:
    <div class="date">'.$entry->updated.'</div>

    This outputs: 2009-04-14T17:37:35Z

    Id like it to output: 14-04-2009 <space> 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:

    Code:
    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

  2. #2

    dhicks's Avatar
    Join Date
    Aug 2005
    Location
    Knightsbridge
    Posts
    5,614
    Thank Post
    1,230
    Thanked 773 Times in 671 Posts
    Rep Power
    235
    Quote Originally Posted by danIT View Post
    Code:
    <div class="date">'.$entry->updated.'</div>
    Could you just use string split?:

    Code:
    <div class="date">'.split("T",$entry->updated)[0].' '.split("Z",split("T",$entry->updated)[1])[0]'</div>
    --
    David Hicks

  3. #3

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29
    Thanks Dhicks but I get the following error:

    unexpected ] was expecting ' or ;

    Can you help?

  4. #4

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Don't bother with a regex, PHP can do this natively in two steps:

    PHP Code:
    $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

  5. Thanks to powdarrmonkey from:

    danIT (15th April 2009)

  6. #5

    Join Date
    Apr 2006
    Location
    UK
    Posts
    939
    Thank Post
    39
    Thanked 70 Times in 54 Posts
    Rep Power
    29
    Worked like a charm, and clearly a much more sensible solution.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 6
    Last Post: 26th November 2008, 01:56 PM
  2. CMIS Timetable cell style expression
    By SimAda00 in forum MIS Systems
    Replies: 4
    Last Post: 28th August 2008, 02:36 PM
  3. Installing Microsoft Expression Web
    By srochford in forum How do you do....it?
    Replies: 11
    Last Post: 12th August 2008, 01:36 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •