Reading Characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
farid
Forum Commoner
Posts: 54
Joined: Thu Nov 11, 2004 4:20 pm
Location: Mexico

Reading Characters

Post 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)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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};
Post Reply