Sub-string without counting blank spaces

后端 未结 3 2040
抹茶落季
抹茶落季 2020-12-21 23:07

I want to make a sub-string, where the $count only counts letters, not spaces. This is what I have so far:

$string =\"vikas tyagi php\";
$strin         


        
3条回答
  •  清歌不尽
    2020-12-21 23:45

    $arr = explode(" ",$str);
    $length = 10;
    for ($i = 0, $currIndex = 0, $finalstring = ""; $currIndex < $length; $i++){
        $finalstring .= " ".substr($arr[$i], 0, $length - $currIndex);
        $currIndex += strlen($arr[$i]);
    }
    

    Here is a demonstration: http://codepad.org/lv4KEsAi

提交回复
热议问题