php根据指定的位置和长度获得子字符串,php的substr函数功能非常强大,不断可以从前往后去子字符串还可以从后往前取字符串
<?php $string = "beginning"; print("Position counted from left: ".substr($string,0,5)."\n"); print("Position counted form right: ".substr($string,-7,3)."\n"); ?>
输出结果:
Position counted from left: begin Position counted form right: gin