简体   繁体   English

strpos总是返回false

[英]strpos always return false

It seems like I'm having an issue with strpos() For some reason, it's always returning false when it should not. 似乎我遇到了strpos()问题,由于某种原因,它总是在不应该返回false情况下返回。

This is where the issue occur : 这是发生问题的地方:

if ( strpos( $attachment_url, $upload_dir_paths['baseurl'] ) !== false ) {
    //some code here
}

I've made a var_dump of $attachment_url and $upload_dir_paths['baseurl'] and compared both values to make sure that the "needle" was in the "haystack" and in fact it was. 我已经制作了$attachment_url$upload_dir_paths['baseurl']var_dump ,并比较了两个值以确保“ needle”位于“ haystack”中,实际上是。

var_dump($upload_dir_paths['baseurl']);    //needle
var_dump($attachment_url);                 //haystack

Results of the var_dump above : 上面的var_dump结果:

string(39) "//localhost:3000/wp-content/uploads"
string(67) "//localhost:3000/wp-content/uploads/2016/10/stunning-photograph.jpg"

Does anyone knows why the if statement is always returning false ? 有谁知道为什么if语句总是返回false

Thanks 谢谢

I think the problem comes from the variable $upload_dir_paths['baseurl']. 我认为问题出在变量$ upload_dir_paths ['baseurl']。
The string "//localhost:3000/wp-content/uploads" is composed of 35 characters unlike the 39 of your question. 字符串“ // localhost:3000 / wp-content / uploads”由35个字符组成,与问题中的39个字符不同。
I think that there are some "hidden" characters that cannot be rendered by your browser/your terminal. 我认为您的浏览器/终端无法呈现某些“隐藏”字符。

How to solve the problem? 如何解决问题?
Maybe try the function " trim " on the variable $upload_dir_paths['baseurl']. 也许尝试在变量$ upload_dir_paths ['baseurl']上使用函数“ trim ”。 It should solve the problem. 它应该解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM