How can I break an string to a an array of characters.
e.g;
$str = "123456";
then after breaking above string, character array would be
$arr = array('1','2','3','4','5','6');
| SitePoint Sponsor |
How can I break an string to a an array of characters.
e.g;
$str = "123456";
then after breaking above string, character array would be
$arr = array('1','2','3','4','5','6');
Do Good Have Good!





str_split (see comments there about php4 compatibility).
But I am using PHP Version: 4.4.2![]()
Do Good Have Good!
thnx I got it![]()
Do Good Have Good!
For php4 just do this which is in php manual:
PHP Code:$str = 'two words';
$array = explode("\r\n", chunk_split($str,1));
print"<pre>";
print_r($array);
To show there is more then one way.
PHP Code:<?php
preg_match_all('/(\w)/', 'abcdefghijklmnopqrstuvwzyz', $regs);
print_r($regs[0]);
Bookmarks