note 11715 deleted from str_pad by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Sat, 03 Mar 2001 21:22:05 +0000 |
| Subject: | note 11715 deleted from str_pad by jmcastagnetto | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11831@lists.php.net to get a copy of this message | ||
[Editor's note: Of course it will not work in this case. You are mixing concepts here, trying
to refer to a regex result inside a function call which takes a string as a parameter. Not a problem
w/ the function but with your logic.]
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";