strstr
文字列の最初の出現を見つけます
関数名:strstr()
該当するバージョン:PHP 4、PHP 5、PHP 7
関数の説明:StrSTR()関数は、指定されたサブストリングを文字列内のサブストリングを見つけ、部分をサブストリングから文字列の端まで返します。サブストリングが見つからない場合、falseが返されます。
構文:strstr(string $ haystack、mixed $ heedle、bool $ before_needle = false):string | false
パラメーター:
返品値:
例:
// 示例1:查找子字符串,并返回从子字符串开始到字符串结尾的部分$haystack = "Hello, world!"; $needle = "world"; $result = strstr($haystack, $needle); echo $result; // 输出:world! // 示例2:查找子字符串,并返回子字符串之前的部分$haystack = "Hello, world!"; $needle = ","; $result = strstr($haystack, $needle, true); echo $result; // 输出:Hello // 示例3:未找到子字符串,返回false $haystack = "Hello, world!"; $needle = "foo"; $result = strstr($haystack, $needle); var_dump($result); // 输出:bool(false)
注: