Page 1 of 1

how split number 3 parts

Posted: Wed Sep 30, 2009 8:09 am
by srdva59
hi,
i have a number with 9 digits lenght
and i want split this number: 922888222
into this: 922 888 222
how can i do that?
thanks a lot for your help :)

Re: how split number 3 parts

Posted: Wed Sep 30, 2009 8:12 am
by Mark Baker
$number = 922888222;
$numberBits = str_split($number,3);

Re: how split number 3 parts

Posted: Wed Sep 30, 2009 8:22 am
by srdva59
hi thanks for your fast feedback but i receive a error: Call to undefined function: str_split() in
may be that function dont work in php4? :x

Re: how split number 3 parts

Posted: Wed Sep 30, 2009 9:48 am
by jackpf
I don't think so.

Read the comments here: http://uk.php.net/str_split

...or just upgrade :/

Re: how split number 3 parts

Posted: Wed Sep 30, 2009 10:44 am
by mayanktalwar1988

Code: Select all

 
<?
$string = "mayanktalwar1988";
$split_length = 3;
 
if(!function_exists('str_split')){
   function str_split($string,$split_length){
 
       $cnt = strlen($string);
 
       for ($i=0; $i < $cnt; $i += $split_length)
           $chunks[]= substr($string,$i,$split_length);    
   
       return $chunks;
   }
}
 
 
$chunks = str_split($string,$split_length);
 
foreach ($chunks as $chunk) {
echo $chunk . " ";
} 
?>
you can do like above if you dont have php5
yes str_split is a php5 specific function...uprade to php5 to use that