为什么strpos函数总是返回false? [英] Why is the strpos function always returning a false?

查看:124
本文介绍了为什么strpos函数总是返回false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我需要让PHP表单检测字符串是否以子字符串DonVito:开头。或不。然而,即使DonVito:存在,它总是返回错误。

Ok, so I need to make the PHP form detect whether a string starts with the substring "DonVito:" or not. However, it''s always returning a false even when DonVito: is present.

展开 | 选择 | Wrap | 行号

推荐答案

这里的问题是 strpos 不会返回布尔值 true 如果找到字符串。但是如果找不到 字符串,它会返回boolean false 。 strpos将返回找到字符串的位置。因此,考虑到这一点,要检查字符串是否在另一个字符串的开头,我们可能会这样做:
The issue here is that strpos does not return a boolean true if the string is found. It does however return boolean false if the string is not found. strpos will return the position at which the string was found. So, with that in mind, to check that a string is at the beginning of another string, we might do:
< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号


感谢。然而,它仍然没有解决。
Thanks. However it''s still unsolved.
展开 | 选择 | Wrap | 行号


对header()的调用将标题添加到HTML的HTML响应中请求。这就是它的全部。它不会中止/关闭脚本/请求。因此,对header()的连续调用将覆盖前一个标题(相同类型)或最后一个标题优先 - 我不确定这里发生了什么(我会在有机会时进行调查)。


考虑到这一点,你必须通过调用退出

编辑:nevermind - 我误读了你的回复。
A call to header() adds headers to the HTML response to an HTML request. That''s all it does. It doesn''t abort/close the script/request. So, successive calls to header() will either overwrite the previous header (of the same type) or the last header will take precedence - I''m not sure what happens here (I''ll investigate when I have chance).

With that in mind, you have to manually terminate the script by calling exit after the header call.

nevermind - I misread what your reply.


这篇关于为什么strpos函数总是返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆