Last Updated: February 25, 2016
·
955
· silvercorp

How to get a string one character at a time

$line = "Hello";

function getChar($line){
    for ($i = 0, $j = strlen($line); $i < $j; $i++) {
          echo $line[$i].', ';
}

2 Responses
Add your response

Hi there, php has a built in for this "str_split".

foreach(str_split('this is a bit cleaner') as $s){
echo $s .', ';
}

all the best
Ross

over 1 year ago ·

@rosscdh thanks! :)

over 1 year ago ·