note 108254 added to function.preg-split

From: Date: Thu, 12 Apr 2012 00:06:18 +0000
Subject: note 108254 added to function.preg-split
Groups: php.notes 
Request: Send a blank email to php-notes+get-187064@lists.php.net to get a copy of this message
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>"; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 120.151.18.169 ---- Manual Page -- http://www.php.net/manual/en/function.preg-split.php Edit -- https://master.php.net/note/edit/108254 Del: integrated -- https://master.php.net/note/delete/108254/integrated Del: useless -- https://master.php.net/note/delete/108254/useless Del: bad code -- https://master.php.net/note/delete/108254/bad+code Del: spam -- https://master.php.net/note/delete/108254/spam Del: non-english -- https://master.php.net/note/delete/108254/non-english Del: in docs -- https://master.php.net/note/delete/108254/in+docs Del: other reasons-- https://master.php.net/note/delete/108254 Reject -- https://master.php.net/note/reject/108254 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#187064) next »