Every once in a blue moon you find yourself needing to take a string and converting it to an array of characters in the string. Maybe it’s because you want to count how often certain letters exist in the string or want to convert the letters to something else. To do this all you need in str_split(). Pass it the string without any additional arguments and you’re good to go:

$letters = str_split('Hello PHPAve.com Readers!!~!');

Additionally, if you wanted to split the string every 2 (or more) characters, you can pass a second argument to determine the length.

$chunks = str_split('Lorem ipsum ... dolor sit amet', 16);

Have you used these functions before? I’d love to hear about how you used them!

Did you enjoy this post?

Cool if I slip into your inbox with more?
Full posts, 1-2 times per week: