chunk_split()
例子:
<!DOCTYPE html> <html> <body> <?php $str = "Shanghai"; echo chunk_split($str,1,"."); ?> </body> </html>
运算结果: S.h.a.n.g.h.a.i.
substr
例子
//使用带有不同正负数的 start 参数:
<!DOCTYPE html> <html> <body> <?php 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 ?> </body> </html>
使用带有不同正负数的 start 和 length 参数:
<!DOCTYPE html> <html> <body> <?php echo substr("Hello world",0,10)."<br>";//Hello worl echo substr("Hello world",1,8)."<br>";//ello wor echo substr("Hello world",0,5)."<br>";//Hello echo substr("Hello world",6,6)."<br>";//world echo substr("Hello world",0,-1)."<br>";//Hello worl echo substr("Hello world",-10,-2)."<br>";//ello wor echo substr("Hello world",0,-6)."<br>";//Hello echo substr("Hello world",-2-3)."<br>";//world ?> </body> </html>