Re: Splitting a string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux