簡體   English   中英

使用php查找字符串中子字符串的出現?

[英]Find the occurences of a substring in string using php?

我需要計算字符串中子字符串出現的次數。

我的代碼像

$str1 = "when he arrives, he want to open the door.";
$find_str = "he";

在這里,字符串“ he”出現了4次。

我如何在php中找到它?

使用substr_count

substr_count($str1, $find_str)

利用substr_count php函數。

解:

$str1 = "when he arrives, he want to open the door.";
$find_str = "he";

substr_count($str1, $find_str);
echo substr_count($str1, $find_str);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM