I'm sure there's an easy solution to this but I'm not sure what it is. I want to put an html break after every character in a small string.
So 'apple' would become 'a<br>p<br>p<br>l<br>e<br>'
Any help would be great, thanks!
<?php function insert_breaks($string){ $length = strlen($string); for($i=0; $i<$length; $i++){ echo $string{$i}."<br>"; } }
Example:
<?php $string = "abcdefghijklmnopqrstuvwxyz"; $length = strlen($string); for($i=0; $i<$length; $i++){ $n = $i+1; echo $string{$i}."<br>"; // NOTE: Curly brackets } ?>
Will output: This . . .
I found that on the substr page of PHP.net. Substr selects a range of characters from a string.
Hope that helps.
~Brett