Re: explode() - quick question
| From: | David Robley | Date: | Thu, 14 Mar 2002 06:10:25 +0000 |
| Subject: | Re: explode() - quick question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-88450@lists.php.net to get a copy of this message | ||
In article <sc8fcf34.018@cis27.hosts.jhmi.edu>, pschwar@jhmi.edu says...
> Im trying to take this string, "hello", and explode it into an array
> with each cell in the array containing one character.
>
> $array[0] = 'h'
> $array[1] = 'e'
> etc..
>
> How does this work? When is use...
>
> $character = explode('', $string) or....
> $character = explode($string)
>
> ...it doesn't seem to work. ANY HELP!?!? THANKS!!
>
You don't need to do that if you just want to reference a particular
position in the string. Each character in a string variable can be
referenced as though the variable is an array of characters. Try:
<?php
$mystring = "hello";
echo $mystring[0]; // outputs h
echo $mystring[4]; outputs o
?>
--
David Robley
Temporary Kiwi!
Quod subigo farinam