PHP Split String | Lessoncup Programming Blog

Saturday, 2 November 2013

PHP Split String

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/>";

}

?>

2 comments :

  1. Provide Output for that so people easily see and try that ....

    ReplyDelete
    Replies
    1. 0 = Lesson 1 = Cup 2 = is 3 = Programming 4 = Blog

      Delete

Mohammad Khasim
Blogger | Web Developer
Hyderabad - INDIA
lessoncup@gmail.com

PHP | My SQL | JQUERY
Web Development Tools | CMS | Frameworks | SEO

Get my Latest Lessons