2013-10-24 73 views
-2

我想測試一個字符串是否在使用PHP的字符串的集合子的存在。測試字符串

例如,

$str="Cycle"; 
$str1="Cycle,Yoga"; 

我要檢查if (str in str1)

+1

使用strpos或功能的strstr可能 – Adam

+1

重複[如何檢查是否字符串包含特定的詞?(http://stackoverflow.com/questions/4366730/how-to-check-if-a-特定的字符串包含字) –

回答

3

利用stripos

if (stripos($str1,$str) !== false) { 
    echo 'true'; 
} 
0

使用strpos或stripos函數

$mystring = 'Cycle,Yoga'; 
$findme = 'Cycle'; 
$pos = strpos($mystring, $findme); 
if ($pos !== false) { 
    echo "true"; 
} 
1

使用strpos(區分大小寫的字符串)或stripos(不區分大小寫)的字符串匹配。

if (strpos($str1,$str) !== false) { 
    // It'll check the case-sensitivity of string 
    echo 'true'; 
} 

if (stripos($str1,$str) !== false) { 
    // It'll ignore the case-sensitivity 
    echo 'true'; 
}