PHP – 使用 iconv_strrpos() 函式查詢字串中最後一次出現的子字串


在 PHP 中,**iconv_strrpos()** 函式用於查詢字串中最後一次出現的子字串。或者,我們可以說 **iconv_strrpos()** 函式返回子字串在目標字串中最後一次出現的字元位置。

語法

string iconv_strrpos(string $haystack, str $needle, str $encoding)

引數

**iconv_strrpos()** 接受三個引數:**$haystack**、**$needle** 和 **$encoding**。

  • **$haystack−** 表示整個字串。

  • **$needle−** $needle 引數用於在給定的整個字串中搜索子字串。

  • **$encoding−** 如果 $encoding 引數不存在或為空,則字串將假定其編碼為 **iconv.internal_encoding**。

返回值

**iconv_strpos()** 返回子字串在目標字串中第一次出現的數值位置。如果找不到子字串,則函式將返回 False。

**注意:** 從 PHP 8.0 版本開始,編碼可以為空;從 PHP 7.1 開始,**iconv_strpos()** 函式支援負偏移量。

示例

 線上演示

<?php
   # UTF-8 string
   $int = iconv_strrpos("hello world!","d", "UTF-8");
   // It will returns the number of character
   var_dump($int);
?>

輸出

int(9)

更新於: 2021年8月23日

201 次瀏覽

啟動你的職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.