Advertisement
Guest User

Untitled

a guest
Feb 8th, 2013
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. function parseTweet($str) {
  2.         $str = preg_replace(
  3.             '@(https?://([-\w\.]+)+(/([\w/_\.]*(\?\S+)?(#\S+)?)?)?)@',
  4.             '<a href="$1">$1</a>',
  5.             $str);
  6.         $str = str_replace('>http://', '>', $str);
  7.         $str = str_replace('>https://', '>', $str);
  8.         $str = preg_replace(
  9.             '/@(\w+)/',
  10.             '<a href="http://twitter.com/$1">@$1</a>',
  11.             $str);
  12.         $str = preg_replace(
  13.             '/\s+#(\w+)/',
  14.             ' <a href="http://search.twitter.com/search?q=%23$1">#$1</a>',
  15.             $str);
  16.         return $str;
  17.     }
  18.  
  19. function daysAgo($time) {
  20.         $now = time();
  21.         $time_ago = $now - $time;
  22.        
  23.         $day = 60*60*24;
  24.        
  25.         $days_ago = floor($time_ago/$day);
  26.        
  27.         $result = "";
  28.        
  29.         if ($days_ago == 0) {
  30.             $result = "Today";
  31.         }
  32.         else if ($days_ago == 1) {
  33.             $result = "Yesterday";
  34.         }
  35.         else {
  36.             $result = $days_ago . " days ago";
  37.         }
  38.        
  39.         return $result;
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement