note 31036 added to function.preg-split
| From: | discordantus dot mapSoN at mac dot com | Date: | Mon, 07 Apr 2003 22:50:14 +0000 |
| Subject: | note 31036 added to function.preg-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46324@lists.php.net to get a copy of this message | ||
I needed to split a string into an array of characters, and couldn't find a built in function
to do it. This:
$array = explode("", $string)
didn't work. So I used this:
$array = preg_split('/(?<=.)(?=.)/', $string);
this uses perl-style regular expressions to split at any point where there is a character behind and
in front of that point.
hope this helps someone!
--
http://www.php.net/manual/en/function.preg-split.php
http://master.php.net/manage/user-notes.php?action=edit+31036
http://master.php.net/manage/user-notes.php?action=delete+31036
http://master.php.net/manage/user-notes.php?action=reject+31036