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
https://forums.phpfreaks.com/topic/38227-string-parsing/#findComment-183541
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
https://forums.phpfreaks.com/topic/38227-string-parsing/#findComment-183546
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
https://forums.phpfreaks.com/topic/38227-string-parsing/#findComment-183565
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.