Page 1 of 1

Posted: Fri Feb 14, 2003 12:39 am
by Redcircle
it's already done for you.. no code really. a string is an array of chars so

Code: Select all

<?php
$string = 'length';
for($x=0; $x<strlen($string); $x++)
{
echo $string[$x].'<br>';
}
?>


would have an output of

l
e
n
g
t
h

Posted: Fri Feb 14, 2003 6:42 am
by PaulG
To take it further and create an array called $arrString:-
<?php
$string = 'length';
for($x=0; $x<strlen($string); $x++)
{
$arrString[$x] = $substr($string, $x, 1);
// you could also do it like this
// $arrString[] = $substr($string, $x, 1);
}
?>