-2

我想使用 php 测试子字符串是否在字符串中。

例如,

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

我想检查一下if (str in str1)

4

3 回答 3

3

利用stripos

if (stripos($str1,$str) !== false) {
    echo 'true';
}
于 2013-10-24T07:09:01.230 回答
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';
}
于 2013-10-24T07:23:24.640 回答
0

使用 strpos 或 stripos

$mystring = 'Cycle,Yoga';
$findme   = 'Cycle';
$pos = strpos($mystring, $findme);
if ($pos !== false) {
    echo "true";
}
于 2013-10-24T07:12:55.887 回答