strpos() ,stripos(),strchr()
1、strpos() 函式返回字串在另乙個字串中第一次出現的位置。如果沒有找到該字串,則返回 false
注:該函式對大小寫敏感即嚴格區分大小寫。
例: <?php
echo strpos("hello world!","wo");
?>
輸出:6
2、stripos()該函式功能和strpos功能相同,但該函式不區分大小寫。
例: <?php
echo stripos("hello world!","or");
?>
輸出為:7
驗證某字串中是否包含某字串:
if(strpos('abc','a') !== false)else
3、strchr()
string
strchr
(string
$haystack
, mixed
$needle
[,bool
$before_needle
=false])
返回 haystack 字串從 needle 第一次出現的位置開始到 haystack 結尾的字串。
注:該函式區分大小寫。如果想要不區分大小寫,請使用 strichr()。
例: <?php
$email
=
'name@example.com'
;
$domain
=
strchr
(
$email
,
'@'
);
echo
$domain
;
//列印@example.com
$user
=
strchr
(
$email
,
'@'
,true);
//從php5.3.0起
echo
$user
;
//列印name
?>
php 採集常用函式 PHP常用採集函式
獲取所有鏈結內容和位址function getallurl code 獲取所有的位址 function getimgsrc code else fnum if fnum fnum 0 return fnum 去除html標記 function text2html txt isu r n txt re...
常用PHP函式
這是一些使用頻率比較高的函式,有的來自別人的程式.1.產生隨機字串函式 function random length return hash 2.擷取一定長度的字串 注 該函式對gb2312使用有效 function wordscut string,length sss 0 for i 0 i le...
PHP常用函式
很有用的一些函式,你可以作為原始碼儲存,然後以後避免重複編寫。檔案讀取函式 檔案讀取函式 function php read file name fclose fd return buf 檔案寫入函式 檔案寫入函式 function php write file name,data,method w...