- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
考虑以下示例:
$a='This is a test';
if(strpos($a,'is a') !== false) {
echo 'True';
}
True
if(strpos($a,'is a') === true) {
echo 'True';
}
!==false
不是
===true
在这种情况下
strpos()
上查看了 PHP 文档但没有找到对此的任何解释。
最佳答案
Because strpos()
never returns true :
Returns the position of where the needle exists relative to the beginning of the haystack string (independent of offset). Also note that string positions start at 0, and not 1.
Returns FALSE if the needle was not found.
if(strpos($a,'is a') == true) {
echo 'True';
}
你通常会得到预期的结果,因为任何正整数都被认为是一个真值,并且因为当你使用
==
时类型杂耍运算符该结果为真。但是,如果字符串位于字符串的开头,则由于返回的零是假值,因此将等同于 false。
关于php - 为什么是 !== false 的 strpos 不是真的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52543130/
Warning: strpos() [function.strpos]: Empty delimiter 是什么意思? 我有这个: if(strpos(''', $text) ===
我知道,有人问过这个问题,但不幸的是,没有解决这个问题的答案。 这出现在我的日志文件中: PHP 消息:PHP 警告:strpos():第 479 行中的字符串中不包含偏移量 不幸的是,我无法理解导致
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界. 这篇CFSDN的博客文章strpos() 函数判断字符串中是否包含某字符串的方法由作者收集整理,
问题,下面是怎么执行echo的: $str = "Hello World"; if (strpos($str, 'He') !== false) { echo 'GOOD'; } 但这不是:
我使用的是 PHP 版本 5.1.6 我有一个字符串( session 文件)并且需要从中提取一个值,所以我在字符串中搜索针但它返回 false,我将代码缩减为: $string = ';SERVER
我正在使用这段代码来查找字符串中是否存在子字符串,但是当它遇到特殊字符时,即使该字符明显存在,它也会失败。 //Code out of context if (strpos($pieces[$i],
所以目前我有以下两个数组: Array ( [0] => image/jpeg [1] => image/png [2] => image/psd ) Array ( [0] => png [1] =
我需要检查字符串是否包含特定单词,但请记住,中间可能有空格(任何类型 - 空格、制表符等)。 $array1 = "name @mail lastname"; $array2 = "name @ ma
因此,我的网站收到了大量垃圾邮件。 为了过滤掉其中的一些内容,我想测试帖子的正文以确保它不包含某些词。如果他们这样做,请立即(临时)禁止用户。 包括我的代码。我添加了一条回显线来显示返回的位置,并测试
我正在尝试使用 strpos 在另一个字符串中查找字符串,但由于某种原因它不适用于某个字符串,即使它适用于另一个字符串。我究竟做错了什么? 结果: true2 预期结果: true1true2 最佳
我在 php 中有一个函数,我想对一个字符串执行简单的搜索,使用 kw 作为搜索短语,如果找到则返回 true。 这是我现在拥有的: for($i=0; $i
我一直在努力反对谷歌试图解决这个问题,但我所能找到的只是那些不明白 strpos 返回找到的字符串的位置的人,所以 0 是一个有效值。这不是我的问题......简而言之: $services=shel
我有一个巨大的 html 代码要扫描。直到现在我一直在使用 preg_match_all从中提取所需的部分。从一开始的问题就是它非常耗费 CPU 时间。我们最终决定使用其他方法进行提取。我在一些文章中
我正在尝试用 PHP 进行一些验证,其中之一是检查输入的字符串中是否有特定的单词。问题是,当我将指定的单词放在第一位时,我的代码似乎无法正常工作。 代码如下: $word = "aa bb cc dd
更新:我在查看strrpos 的文档时认为它是strpos 的文档。很抱歉犯了这个愚蠢的错误。 根据 the docs ,它表示当您提供一个负值作为偏移量参数时,该函数将从字符串末尾开始那么多字符,向
我在 stackoverflow 上找到了这个例子: if (strpos($a,'are') !== false) { echo 'true'; } 但是我如何让它搜索两个词。我需要这样的东
我需要找出一个字符串是否存在于数组值中,但不一定是实际的数组值。 $array = array( 0 => 'blue', 1 => 'red', 2 =>
仅当 $_GET['page'] 参数包含文本“mytext-”时,我才需要执行一些脚本 查询字符串是:admin.php?page=mytext-option 这将返回 0: $myPage = $
我已经为我的网络应用编写了一个基本的“安全检查程序”。我需要看一眼用户提交的代码是否包含恶意内容。 这是我现在正在运行的代码的屏幕截图:http://cl.ly/677a6dc40034f096697
我正在使用 strpos() 函数在数组键成员中查找字符串。 foreach($_POST as $k => $v){ // for all types of questions of
我是一名优秀的程序员,十分优秀!