Monday, 26 August 2013

Finding a character at a specific position of a string

Finding a character at a specific position of a string

Since I am still new to PHP, I am looking for a way to find out how to get
a specific character from a string.
Example:
$word = "master";
$length = strlen($word);
$random = rand(1,$length);
So let's say the $random value is 3, then I would like to find out what
character the third one is, so in this case the character "s". If $random
was 2 I would like to know that it's a "a".
I am sure this is really easy, but I tried some substr ideas for nearly an
hour now and it always fails.
Your help would be greatly appreciated.

No comments:

Post a Comment