Re: Splitting a string

From: Date: Wed, 15 Nov 2006 05:24:25 +0000
Subject: Re: Splitting a string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-244645@lists.php.net to get a copy of this message
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

« previous php.general (#244645) next »