Markavian

Convert English Date (DD/MM/YYYY) to (YYYY-MM-DD) from file

Nov 17th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.42 KB | None | 0 0
  1. <?php
  2.  
  3. define("NL", "\n");
  4.  
  5. $file = file("dates.txt");
  6.  
  7. foreach($file as $key=>$line)
  8. {
  9.     $line = trim($line);
  10.    
  11.     if($line)
  12.     {
  13.         $split = explode('/', $line);
  14.        
  15.         $day = $split[0];
  16.         $month = $split[1];
  17.         $year = $split[2];
  18.        
  19.         $date = $year . '-' . $month . '-' . $day;
  20.         printHTML($date);
  21.     }
  22. }
  23.  
  24. function printHTML($string, $tag='pre')
  25. {
  26.     echo '<' . $tag . '>' . $string . '</' . $tag . '>' . NL;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment