php splitting large numbers (like explode) -


i need functionality of php explode(), without separators.

for example, turning variable "12345" array, holding each number seperately.

is possible? i've googled found explode(), doesn't seem work.

thanks!

with string in php:

$foo="12345"; echo $foo[0];//1 echo $foo[1];//2 //etc 

or (from preg_split()) page in manual

$str = 'string'; $chars = preg_split('//', $str, -1, preg_split_no_empty); print_r($chars); 

even better:

$str = 'string'; $chars=str_split($str, 1) print_r($chars); 

benchmark of preg_split() vs str_split()

 function microtime_float() {     list($usec, $sec) = explode(" ", microtime());     return ((float)$usec + (float)$sec); }   $str = '12345'; $time_start = microtime_float(); ($i = 0; $i <100000; $i++) { $chars = preg_split('//', $str, -1, preg_split_no_empty); //$chars=str_split($str, 1); } $time_end = microtime_float(); $time = $time_end - $time_start;  echo "$time seconds\n"; 

results:

str_split  =0.69 preg_split =0.9 

Comments

Popular posts from this blog

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

apache - Add omitted ? to URLs -

php - How can I stop spam on my custom forum/blog? -