<?php
//my own myExplode function
function myExplode($string){
$length = strlen($string);
$word = "";
$words = array();
for($i = 0; $i < $length; $i++){
if( $string[$i] == " " || $i == $length -1 || $string[$i] == "\n"){
if($i == $length - 1){
$word .= $string[$i];
}
if(!empty($word)){
$words[] = $word;
}
$word = "";
} else{
$word .= $string[$i];
}
}
return $words;
}
//single line conversion into array
print_r(myExplode("My name \nis polo dev"));
echo '<br>';
//multi line conversion into array
$paragraph = "hello my name is shibu dev polo
I live in dhaka city
I graduated in marketing
but want to be IT professional
take care";
print_r(myExplode($paragraph));
//my own myExplode function
function myExplode($string){
$length = strlen($string);
$word = "";
$words = array();
for($i = 0; $i < $length; $i++){
if( $string[$i] == " " || $i == $length -1 || $string[$i] == "\n"){
if($i == $length - 1){
$word .= $string[$i];
}
if(!empty($word)){
$words[] = $word;
}
$word = "";
} else{
$word .= $string[$i];
}
}
return $words;
}
//single line conversion into array
print_r(myExplode("My name \nis polo dev"));
echo '<br>';
//multi line conversion into array
$paragraph = "hello my name is shibu dev polo
I live in dhaka city
I graduated in marketing
but want to be IT professional
take care";
print_r(myExplode($paragraph));
No comments:
Post a Comment