Saturday, August 29, 2015

break the string into array manually using php like explode()

<?php
$string = "Hi how are you again bangladesh";
$length = strlen($string);
$words = array();
$new_string = "";
for($j = 0; $j < $length; $j++){
    if($string[$j] == " " || $j == $length-1){
        if($j == $length-1){
            $new_string .= $string[$j];
        }
        $words[] = $new_string;
        $new_string = "";
    }
    else{
        $new_string .= $string[$j];
    }
}

print_r($words);

No comments:

Post a Comment

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }