定義
strstr - 按分隔符截取字串
語法
strstr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] ) : string
回傳 haystack 字串從 needle 第一次出現的位置開始到 haystack 結尾的字串,包括needle,
不存在則回傳false,
如果僅僅想確定 needle 是否存在于 haystack 中,可以使用速度更快、耗費記憶體更少的 strpos() 函式,
before_needle 如果為true,則回傳 needle 在 haystack 中的位置之前的部分,不包括needle,
示例
<?php
$email = '[email protected]';
$domain = strstr($email, '@');
echo $domain; // @example.com
$user = strstr($email, '@', true); // 從 PHP 5.3.0 起
echo $user; // name,不包含@
?>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/51273.html
標籤:PHP
