本教程操作环境:windows10系统、PHP7.1版、DELL G3电脑
php怎么分割字符串取前几位
substr() 函数返回字符串的一部分。
注释:如果 start 参数是负数且 length 小于或等于 start,则 length 为 0。
语法
立即学习“PHP免费学习笔记(深入)”;
substr(string,start,length)
其中参数设置如下表所示:
示例如下:
";echo substr("Hello world",1,8)."
";echo substr("Hello world",0,5)."
";echo substr("Hello world",6,6)."
"; echo substr("Hello world",0,-1)."
";echo substr("Hello world",-10,-2)."
";echo substr("Hello world",0,-6)."
";echo substr("Hello world",-2-3)."
";?>输出结果:
推荐学习:《php视频教程》

