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.

Thanks again.

On Wednesday 15 November 2006 06:24, Paul Novitski wrote:
> At 11/14/2006 03:17 PM, Børge Holen wrote:
> >$number = 123456789
> >
> >should print as following:
> >var1: 12345   (and it is this lengt witch varies)
> >var2: 67
> >var3: 89.
>
> You can also do this with a regular expression:
>
> $iNumber = '123456789';
> $sPattern = '/(\d+)(\d{2})(\d{2})$/';
> preg_match($sPattern, $iNumber, $aMatches);
>
> Then $aMatches contains:
>
> Array
> (
>      [0] => 123456789
>      [1] => 12345
>      [2] => 67
>      [3] => 89
> )
>
> The regexp pattern /(\d+)(\d{2})(\d{2})$/ means:
>
>          (one or more digits) (two digits) (two digits) [end of string]
>
> preg_match
> http://ca3.php.net/manual/en/function.preg-match.php
>
> Pattern Syntax
> http://ca3.php.net/manual/en/reference.pcre.pattern.syntax.php
>
> Regards,
> Paul

-- 
---
Børge
Kennel Arivene 
http://www.arivene.net
---

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

Reply via email to