閱讀89 返回首頁    go 阿裏雲 go 技術社區[雲棲]


php之substr()詳解

定義和用法

substr() 函數返回字符串的一部分。

語法

substr(string,start,length)
參數 描述
string 必需。規定要返回其中一部分的字符串。
start

必需。規定在字符串的何處開始。

  • 正數 - 在字符串的指定位置開始
  • 負數 - 在從字符串結尾的指定位置開始
  • 0 - 在字符串中的第一個字符處開始
length

可選。規定要返回的字符串長度。默認是直到字符串的結尾。

  • 正數 - 從 start 參數所在的位置返回
  • 負數 - 從字符串末端返回

提示和注釋

注釋:如果 start 是負數且 length 小於等於 start,則 length 為 0。

例子

例子 1

<?php
echo substr("Hello world!",6);
?>

輸出:

world!

例子 2

<?php
echo substr("Hello world!",6,5);
?>

輸出:

world

最後更新:2017-04-03 05:38:56

  上一篇:go 架設某大型網站服務器全部詳細過程(鬱悶少年)
  下一篇:go php之內存管理基礎