Re: Splitting a string
| From: | Paul Novitski | Date: | Thu, 16 Nov 2006 00:38:47 +0000 |
| Subject: | Re: Splitting a string | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244704@lists.php.net to get a copy of this message | ||
At 11/15/2006 02:06 PM, Børge Holen wrote:
Oh this was good. I added a while loop to insert extra strings "0" in front of the number to add if the string is less than 5 chars short. I forgot to mentinon that the string actually could be shorter (just found out) and the code didn't work with fewer than 5 char strings. But now is rocks.Hey Børge, If you need to left-pad with zeroes, PHP comes to the rescue: http://php.net/str_pad However, if you're using the regular expression method then you might not need to pad the number. You can change the pattern from this:
/(\d+)(\d{2})(\d{2})$/'
to this:
/(\d*)(\d{2})(\d{2})$/'
so it won't require any digits before the final two pairs.
* 0 or more quantifier
+ 1 or more quantifier
http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php
Paul