Can I split a string word by word into an array by using PHP?
example:
$string = "hello";
then, split string into "h", "e", "l", "l", "o".
thanks
Can I split a string word by word into an array by using PHP?
example:
$string = "hello";
then, split string into "h", "e", "l", "l", "o".
thanks
There's a function just for that
The above will output:PHP Code:$string = 'Hello there!';
$array = str_split($string);
print_r($array);
So the function you need is str_split. You can also choose to split the string every 2 letters, 3 letters, or whatever you desire, but the default will split every letter into it's own array key.Code:Array ( [0] => H [1] => e [2] => l [3] => l [4] => o [5] => [6] => t [7] => h [8] => e [9] => r [10] => e [11] => ! )
View PHP.net for more info.
If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:
Similarly, you can just use explode() if you split by null:
PHP Code:// returns an array with each character:
explode("Hello there!", "");
- When in doubt, refer to the PHP manual.
Waw, that is great. Thanks.