Page 1 of 1

Reading Characters

Posted: Tue Dec 14, 2004 9:32 am
by farid
:oops: :lol:
Hi Y'all!!

I have a problem when I try to read each character from the value of a variable, that is:

$value="AB CD EF";

So I can not make that the code reads each and every one of the characters from $value, like reading A and keeping it in an array, and then the B and keeping in other position of the same array, and so on, and so on.

Thanks!!
:lol: 8)

Posted: Tue Dec 14, 2004 9:42 am
by timvw
you can reference to a given character like this:

Code: Select all

$string = "RTFM";
echo $string{1}
//outputs R
with strlen you can get the lenght of the string...

Code: Select all

$string = "RTFM";
$len = strlen($string);
for ($i = 0; $i < $len; ++$i)
  echo $string{$i};