Break Up A Variable Into Individual Characters

Hey,

What I want to do is be able to break up a variable into individual characters… like this:

If I had:
$var = “PointlessThings.com”;

It would break it up into:
$char1 = “P”;
$char2 = “o”;
$char3 = “i”;

$char19 = “m”;

Is that possible?

Thanks,

Nick

$str = “Hello Friend”;

$arr1 = str_split($str);
$arr2 = str_split($str, 3);

print_r($arr1);
print_r($arr2);

/* Output may look like:

Array
(
[0] => H
[1] => e
[2] => l
[3] => l
[4] => o
[5] =>
[6] => F
[7] => r
[8] => i
[9] => e
[10] => n
[11] => d
)

Array
(
[0] => Hel
[1] => lo
[2] => Fri
[3] => end
)
*/

Thanks, but when I tried it out, it returned this error:

Fatal error: Call to undefined function: str_split() in /home/u1/pointless/temp/html/test2.php on line 5

$arr1 = str_split($str); is what is on line 5

-Nick

str_split() is for PHP 5.0

You could use a loop and the substr() function, however to achieve what you are looking for.

http://us2.php.net/manual/en/function.substr.php

Thank you!

-Nick

Sponsor our Newsletter | Privacy Policy | Terms of Service