note 108254 rejected from function.preg-split by mazzanet

From: Date: Thu, 12 Apr 2012 06:23:02 +0000
Subject: note 108254 rejected from function.preg-split by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187078@lists.php.net to get a copy of this message
Note Submitter: admin at lonweigh dot org dot au ---- I would like to split a array of text that but i need it to split at a certain number of characters in to the array. i.e. to split at $string='499RED92Gary' I would like to split at 9 and R i.e. at the end of 499 and start of RED. And then to do another split after D and before 9. This is for different string but the strings are consistant i.e. another string may have $string='533OGE92Pete'. So a split would need to be done between 533 and OGE and similarly between 92 and Gary. What i want is the 4th to 5th charcters in the string I then wanted to assign this OGE or RED to a string. Would preg_split be able to do this or would it be somthing like to use explode. At the moment i have the following which works if theres a comma but doesnt if there not <?php $string='499RED92Gary'; $result =preg_split("/,\s*/", $string, -1); foreach ($result as $x) { print "x: $x<br>"; } ?>

« previous php.notes (#187078) next »