php_joe Posted September 22, 2006 Share Posted September 22, 2006 I want to break up a word into it's individual letters so that I can stick things between them, reverse them, whatever.I knocked up this bit of code:[code]$word = "Mary had a little lamb";$wordcount = strlen($word);$i = "0";while($i < $wordcount){$key = "$i";echo "$word[$key]";$i = ($i + 1);}[/code]which works, but I'm sure that there's a better way to do it. Is there a way to explode the characters in the text or something?Thanks,Joe Quote Link to comment Share on other sites More sharing options...
effigy Posted September 22, 2006 Share Posted September 22, 2006 [code]<pre><?php $string = 'Mary had a little lamb'; $pieces = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); print_r($pieces);?></pre>[/code] Quote Link to comment Share on other sites More sharing options...
php_joe Posted September 23, 2006 Author Share Posted September 23, 2006 Thank you very much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.