日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:52003
  • 待審:43
  • 小程序:12
  • 文章:1047590
  • 會員:762

php提供多種字符串截取函數:substr():截取字符串指定部分。substring():從字符串末尾向起始位置截取子字符串。substr_replace():替換字符串指定部分。str_replace():替換字符串指定部分為其他部分。

PHP 中截取字符串的函數

PHP 提供了多種函數來截取字符串,其中最常用的包括:

substr(): 將字符串的一部分(子字符串)截取并返回。其語法為:substr(string $string, int $start, int $length = null),其中 $start 指定子字符串的起始位置,$length 指定子字符串的長度。

例如:

<code class="php">$string = "Hello World!";
$substring = substr($string, 0, 5); // "Hello"</code>

登錄后復制

substring(): 功能與 substr() 類似,但從字符串末尾向起始位置截取子字符串。其語法為:substring(string $string, int $start, int $length = null),其中 $start 指定子字符串的起始位置,$length 指定子字符串的長度。

例如:

<code class="php">$string = "Hello World!";
$substring = substring($string, 10, 5); // "World"</code>

登錄后復制

substr_replace(): 用指定字符串替換字符串中的一部分。其語法為:substr_replace(string $string, string $replacement, int $start, int $length = null),其中 $start 指定替換的起始位置,$length 指定替換的長度。

例如:

<code class="php">$string = "Hello World!";
$substring = substr_replace($string, "there", 7, 5); // "Hello there!"</code>

登錄后復制

str_replace(): 將字符串中的某些部分替換為其他部分。其語法為:str_replace(mixed $search, mixed $replace, mixed $subject),其中 $search 指定要替換的部分,$replace 指定替換后的部分,$subject 指定目標字符串。

例如:

<code class="php">$string = "Hello World!";
$substring = str_replace("World", "there", $string); // "Hello there!"</code>

登錄后復制

分享到:
標簽:PHP 函數 字符串 截取
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 52003

    網站

  • 12

    小程序

  • 1047590

    文章

  • 762

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定