Stickybomb Posted February 12, 2007 Share Posted February 12, 2007 Hi im a little new to php and was wondering how i would go aout taking a binary number such as 011001 and dumping each character into an array say array[0]=0,array[1],array[2]=1 you get the idea if anyone can assist me with this I would be greatfull thks Stickybomb* Quote Link to comment https://forums.phpfreaks.com/topic/38227-string-parsing/ Share on other sites More sharing options...
Daniel0 Posted February 12, 2007 Share Posted February 12, 2007 $array = str_split($binary_number); Quote Link to comment https://forums.phpfreaks.com/topic/38227-string-parsing/#findComment-183086 Share on other sites More sharing options...
redarrow Posted February 12, 2007 Share Posted February 12, 2007 <?php $num="123456789"; $res=explode($num); //array format now is: print_f($res); foreach($res as $result){ echo "$result <br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/38227-string-parsing/#findComment-183087 Share on other sites More sharing options...
Stickybomb Posted February 13, 2007 Author Share Posted February 13, 2007 $array = str_split($binary_number); looking for php 4 way of doing this str_split is only available in version 5 <?php $num="123456789"; $res=explode($num); //array format now is: print_f($res); foreach($res as $result){ echo "$result <br>"; } ?> Wrong parameter count for explode() there are some minor things wrong with this that i did fix, however its giving me an error "Wrong parameter count for explode()" Quote Link to comment https://forums.phpfreaks.com/topic/38227-string-parsing/#findComment-183541 Share on other sites More sharing options...
ToonMariner Posted February 13, 2007 Share Posted February 13, 2007 that is becase explode must have a delimiter to split the string on. You need str_split($num); Quote Link to comment https://forums.phpfreaks.com/topic/38227-string-parsing/#findComment-183542 Share on other sites More sharing options...
Stickybomb Posted February 13, 2007 Author Share Posted February 13, 2007 that is becase explode must have a delimiter to split the string on. You need str_split($num); as stated before looing for way of doing this in version 4 "Call to undefined function: str_split()" also when using seperator like so i am getting a parseing error <?php $num="0-1-1-0-1"; $res=explode(-, $num); print($res); ?> Quote Link to comment https://forums.phpfreaks.com/topic/38227-string-parsing/#findComment-183546 Share on other sites More sharing options...
kenrbnsn Posted February 13, 2007 Share Posted February 13, 2007 You need to put strings in quotes: <?php $num = '0-1-1-0-1'; $res = explode('-',$num); echo '<pre>' . print_r($res,true) . '</pre>'; ?> You can also use strings like arrays: <?php $res = array(); $num = '101101'; for($i=0;$i<strlen($num);$i++) $res[] = $num[$i]; echo '<pre>' . print_r($res,true) . '</pre>'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/38227-string-parsing/#findComment-183565 Share on other sites More sharing options...
Stickybomb Posted February 13, 2007 Author Share Posted February 13, 2007 thks worked gret Quote Link to comment https://forums.phpfreaks.com/topic/38227-string-parsing/#findComment-183568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.