php下使用strpos需要注意===运算符
PHP 使用 需要 运算符 注意 strpos
2023-06-13 09:14:23 时间
<?php
/*
判断字符串是否存在的函数
*/
functionstrexists($haystack,$needle){
return!(strpos($haystack,$needle)===FALSE);//注意这里的"==="
}
/*
Test
*/
$mystring="abc";
$findme="a";
$pos=strpos($mystring,$findme);
//Noteouruseof===.Simply==wouldnotworkasexpected
//becausethepositionof"a"wasthe0th(first)character.
//简单的使用"=="号是不会起作用的,需要使用"===",因为a第一次出现的位置为0
if($pos===false){
echo"Thestring"$findme"wasnotfoundinthestring"$mystring"";
}else{
echo"Thestring"$findme"wasfoundinthestring"$mystring"";
echo"andexistsatposition$pos";
}
//Wecansearchforthecharacter,ignoringanythingbeforetheoffset
//在搜索字符的时候可以使用参数offset来指定偏移量
$newstring ="abcdefabcdef";
$pos =strpos($newstring,"a",1);//$pos=7,not0
?>
相关文章
- 【笔记php】如何使用PHP从JSON提取数据?
- 如何使用PHP连接MySQL数据库(php如何关联mysql)
- 数据如何使用PHP在MySQL中添加数据(php添加mysql)
- 使用PHP执行Linux脚本:简单而快速!(php执行linux脚本)
- PHP如何使用Redis连接: 代码实例(php连接redis代码)
- PHP使用Redis实现数据存储(php连接redis)
- PHP实现Oracle数据库连接(php支持oracle)
- 如何使用PHP重启Linux服务:简易教程(php重启linux服务)
- 使用Linux命令行来优化你的PHP开发(linux命令行php)
- 技术使用PHP与MSSQL高效连接:实现无缝关联(php连接mssql的)
- 从头到尾:使用PHP进行MSSQL手工注入(php手工注入mssql)
- 使用PHPMSSQL实现数据库操作(php加mssql)
- 如何使用Linux 查找安装PHP的位置?(linux查找php)
- 使用PHP和MySQL研究论文(php mysql 论文)
- 馆PHP编程与MySQL建立图书馆管理系统(php mysql 图书)
- 文件Linux 下如何快速删除PHP文件(linux 删除php)
- 使用PHP连接Redis应用的指南(redis连接 php)
- PHP开发中常用的三个表单验证函数使用小结
- PHP得到某段时间区间的时间戳php定时任务
- 使用php实现下载生成某链接快捷方式的解决方法
- PHP中nowdoc和heredoc使用需要注意的一点