note 80003 deleted from function.split by felipe
| From: | felipe@php.net | Date: | Mon, 24 Dec 2007 13:13:02 +0000 |
| Subject: | note 80003 deleted from function.split by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133972@lists.php.net to get a copy of this message | ||
Note Submitter: Svetoslav Marinov
----
Sometimes it is useful to split a string by every character as you can do with Perl:
my @a = split('', 'abc');
/**
* @desc Splits the string by each char
* @param string
* @param int
* @return array
* @author Svetoslav Marinov <svetoslavm AT gmail.com>
*/
function dev_split($str, $max = 7) {
$data = array();
if (strlen($str) < $max) {
$max = strlen($str);
}
// pic a char at a time.
for ($i = 0; $i < $max; $i++) {
$data[] = substr($str, $i, 1);
}
return $data;
}