手机
当前位置:查字典教程网 >编程开发 >php教程 >php下使用strpos需要注意 === 运算符
php下使用strpos需要注意 === 运算符
摘要:复制代码代码如下:

复制代码 代码如下:

<?php

/*

判断字符串是否存在的函数

*/

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.

// 简单的使用 "==" 号是不会起作用的,需要使用 "===",因为 a 第一次出现的位置为 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

// 在搜索字符的时候可以使用参数 offset 来指定偏移量

$newstring= 'abcdef abcdef';

$pos= strpos($newstring, 'a', 1); // $pos = 7, not 0

?>

【php下使用strpos需要注意 === 运算符】相关文章:

关于PHP中操作MySQL数据库的一些要注意的问题

php使用GD实现颜色渐变实例

PHP SPL标准库中的常用函数介绍

php三元运算符知识汇总

php环境上传大文件需要注意的事项

PHP学习之PHP运算符

PHP中使用curl入门教程

PHP错误Warning:mysql_query()怎么办?

php中smarty变量修饰用法实例分析

php使用post数组的键值创建同名变量并赋值的方法

精品推荐
分类导航