Re: note 11715 added to str_pad
| From: | Jesus M. Castagnetto | Date: | Sat, 03 Mar 2001 19:20:08 +0000 |
| Subject: | Re: note 11715 added to str_pad | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-11826@lists.php.net to get a copy of this message | ||
I will add the following to the top of your note:
[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.]
If you prefer it being deleted, let me know ASAP.
--- rob@OhReally.com wrote:
> 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
>
>
> --
> PHP Notes Mailing List (http://www.php.net/)
> To unsubscribe, e-mail:
> php-notes-unsubscribe@lists.php.net
> For additional commands, e-mail:
> php-notes-help@lists.php.net
> To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
>
=====
--- Jesus M. Castagnetto <jmcastagnetto@php.net>
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/