note 11715 added to str_pad
| From: | rob at OhReally dot com | Date: | Sat, 03 Mar 2001 17:40:17 +0000 |
| Subject: | note 11715 added to str_pad | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11817@lists.php.net to get a copy of this message | ||
str_pad will not work inside a regexp.
suppose you have a date "3-3-2001" and you would like to get it back as
"2001-03-03", the following will NOT work:
$newdate = ereg_replace("([0-9]+)-([0-9]+)-([0-9]+)",
"\\3-".str_pad("\\2", 2, "0",
STR_PAD_LEFT)."-".str_pad("\\1", 2, "0", STR_PAD_LEFT), $date);
you will have to work around it with something like
ereg("([0-9]+)-([0-9]+)-([0-9]+)", $date, $parts);
$d = str_pad($parts[1], 2, "0", STR_PAD_LEFT);
$m = str_pad($parts[2], 2, "0", STR_PAD_LEFT);
$y = $parts[3];
$newdate = "$y-$m-$d";
http://www.php.net/manual/nl/function.str-pad.php