Splitting a string is very useful task to developers and many web developers has face it, but i will show you the simple way how we split the string having some special characters, basically we add the words separated by comma, to split the string we use explode() function. this function breaks the string into an array. this function have 3 parameters implode(separator, string, limit) the third parameter is optional.
i will show the best example to splitting the string and displaying the result using different types of Loops
<?php $someWords = "Lesson Cup is Programming Blog"; $wordsplit = explode(" ", $someWords); foreach($wordsplit as $red=>$val){ echo $red.' = '.$val."<br/>"; } $i=0; while($i<count($wordsplit)){ echo "$i = $wordsplit[$i] <br/>"; $i++; } for($i=0;$i<count($wordsplit);$i++){ echo "$i = $wordsplit[$i] <br/>"; } ?>
Provide Output for that so people easily see and try that ....
ReplyDelete0 = Lesson 1 = Cup 2 = is 3 = Programming 4 = Blog
Delete