View Single Post
Ambitious contributor
18Aug2010,03:48  
pein87's Avatar
This function breaks a piece of text into characters and shows them on a newline. I could not for the love of me get the \n to work so I added <br /> instead.


PHP Code:
<?php
function textToCharacters($string)
{
    
$sLen strlen($string); // length in numbers of the text
    
$i 0// iteration start point
    
$characters "";
    
    for(
$i 0$i $sLen$i++) // iterate from 0 to length of the string
    
{

        
$characters .= $string[$i]. "<br />"// store each character as a space seperated array.

    
}

    return 
$characters// return the list of the characters

}

echo 
textToCharacters("pein87");


?>
Tested and works shows
p
e
i
n
8
7
in the browser
shabbir like this