split string after x characters

后端 未结 2 1125
醉酒成梦
醉酒成梦 2020-12-14 14:35

How to split $string after 5 characters into an array

example:

$string=\"123456789\";

expected output

$output[0] co         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 14:52

    With the help of BoltClocks' answer I have created the following function to solve the problem:

    function split_on($string, $num) {
        $length = strlen($string);
        $output[0] = substr($string, 0, $num);
        $output[1] = substr($string, $num, $length );
        return $output;
    }
    

提交回复
热议问题