在x个字符后分割字符串 [英] split string after x characters

查看:84
本文介绍了在x个字符后分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将5个字符后的$ string拆分为一个数组

How to split $string after 5 characters into an array

示例:

$string="123456789";

预期产量

$output[0] contain "12345";
$output[1] contain "6789";

推荐答案

借助BoltClocks的答案,我创建了以下函数来解决该问题:

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;
}

这篇关于在x个字符后分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆