RE: [PHP] breaking up a string (every N chars)

From: Date: Tue, 27 May 2003 02:49:17 +0000
Subject: RE: [PHP] breaking up a string (every N chars)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-149033@lists.php.net to get a copy of this message
Can also use: preg_match_all('/.{3}/',$String,$ar); $ar[0] will be your array of matches. Array ( [0] => Array ( [0] => 001 [1] => 102 [2] => 203 [3] => 304 [4] => 405 ) ) (shown to be slightly faster than the below in my tests, but do your own benchmarks) ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ > -----Original Message----- > From: Evan Nemerson [mailto:evan@coeus-group.com] > Sent: Monday, May 26, 2003 9:46 PM > To: php-general@lists.php.net > Subject: Re: [PHP] breaking up a string (every N chars) > > php.net/chunk_split > php.net/explode > > explode("\r\n", trim(chunk_split($String, 3, "\r\n"))); > > > On Monday 26 May 2003 06:16 pm, zavaboy wrote: > > Hi, How can I break a string every N (eg: 3) characters? > > > > //Suppose I have a string... > > $String = "001102203304405"; > > //Now, how do I break this string every 3 characters? > > //So... > > $String[0] = "001"; > > $String[1] = "102"; > > $String[2] = "203"; > > $String[3] = "304"; > > $String[4] = "405"; > > > > Thanks in advance! > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#149033) next »