PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
srdva59
Forum Commoner
Posts: 77 Joined: Sun Feb 15, 2009 10:58 am
Post
by srdva59 » Wed Sep 30, 2009 8:09 am
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
Mark Baker
Forum Regular
Posts: 710 Joined: Thu Oct 30, 2008 6:24 pm
Post
by Mark Baker » Wed Sep 30, 2009 8:12 am
$number = 922888222;
$numberBits = str_split($number,3);
srdva59
Forum Commoner
Posts: 77 Joined: Sun Feb 15, 2009 10:58 am
Post
by srdva59 » Wed Sep 30, 2009 8:22 am
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?
mayanktalwar1988
Forum Contributor
Posts: 133 Joined: Wed Jul 08, 2009 2:44 am
Post
by mayanktalwar1988 » Wed Sep 30, 2009 10:44 am
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