PHP字串包含判斷

旭東的部落格發表於2017-08-03

遇到了這個問題。記錄一下。用strpos查詢字串來進行字串包含判斷。

 1 <?php
 2     //$res = strpos("hello", "hx");
 3     $res = strpos("hello", "he");
 4     if ($res !== false){
 5         echo "find OK, pos:$res
";
 6     }   
 7     else {
 8         echo "find failed, not exist
";
 9     }   
10 ?>

更多可以看w3school的函式說明

http://www.w3school.com.cn/php/func_string_strpos.asp


相關文章