字符串截取
substr()
作用:
函数返回字符串的一部分。
语法:
substr(string,start,length)
string: 需要截取的字符串(必填)
start : 开始位置(必填)
length: 截取长度(可选)
echo substr("Hello world",10)."<br>"; //d
echo substr("Hello world",1)."<br>"; //ello world
echo substr("Hello world",3)."<br>"; //lo world
echo substr("Hello world",7)."<br>"; //orld
echo substr("Hello world",-1)."<br>"; //d
echo substr("Hello world",-10)."<br>"; //ello world
echo substr("Hello world",-8)."<br>"; //lo world
echo substr("Hello world",-4)."<br>"; //orld
开始位置为正整数时,从前往后截取.
开始位置为负整数时,从后往前截取.