Jump to content

String parsing


Stickybomb

Recommended Posts

$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()"

Link to comment
Share on other sites

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);


?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.