Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   php text to characters function (http://www.go4expert.com/forums/php-text-characters-function-t23041/)

pein87 18Aug2010 03:48

php text to characters function
 
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

johnny.dacu 23Aug2010 13:28

Re: php text to characters function
 
Well... i don't think is a text to chars function. More like a text to text function because the output is after all another string. :)

pein87 24Aug2010 05:07

Re: php text to characters function
 
it break the original string into characters and shows them on a newline. Of course you dont need a function to get the text thats saved as a variable into characters you could of course just use $text[0].


All times are GMT +5.5. The time now is 03:13.