note 11717 added to str_pad
| From: | php-general at lists dot php dot net | Date: | Sat, 03 Mar 2001 20:34:32 +0000 |
| Subject: | note 11717 added to str_pad | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11828@lists.php.net to get a copy of this message | ||
To reformat the date "3-3-2001" to "2001-03-03" you would use this regexp:
$newdate = preg_replace("/([0-9]+)-([0-9]+)-([0-9]+)/ie",
"'\\3-'.str_pad('\\2', 2, '0',
STR_PAD_LEFT).'-'.str_pad('\\1', 2, '0', STR_PAD_LEFT)", $date);
http://www.php.net/manual/en/function.str-pad.php