色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php下使用strpos需要注意 === 運(yùn)算符

復(fù)制代碼 代碼如下:
<?php
/*
判斷字符串是否存在的函數(shù)
*/
function strexists($haystack, $needle) {
return !(strpos($haystack, $needle) === FALSE);//注意這里的"==="
}
/*
Test
*/
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);

// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
// 簡單的使用 "==" 號是不會起作用的,需要使用 "===",因?yàn)?a 第一次出現(xiàn)的位置為 0
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}

// We can search for the character, ignoring anything before the offset
// 在搜索字符的時(shí)候可以使用參數(shù) offset 來指定偏移量
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0
?>

php技術(shù)php下使用strpos需要注意 === 運(yùn)算符,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 洱源县| 原平市| 大理市| 桓台县| 四子王旗| 贡觉县| 栖霞市| 正蓝旗| 乌海市| 昭通市| 平江县| 丰原市| 南城县| 东丰县| 宿松县| 靖江市| 宜黄县| 道孚县| 怀安县| 将乐县| 铁岭市| 泰兴市| 东港市| 清水河县| 凯里市| 漠河县| 车险| 丘北县| 大石桥市| 利津县| 武隆县| 吉木萨尔县| 余江县| 湖州市| 望奎县| 曲沃县| 广东省| 正阳县| 子洲县| 东光县| 长垣县|