我有这个网址“ https://www.example.com/thymus_vulgaris?tag=Oil&page=2” 我从php中的 $ _ SERVER ['REQUEST_URI'] 那里获得 / thymus_vulgaris?tag = Oil&page = 2 而且我还将与变量相同的URL保存在数据库中 $ abc = / thymus_vulgaris?tag = Oil&page = 2 您可以看到两个URL URI相同我正在编写此代码。 但无法进行比较,请查看屏幕截图值以更好地了解
foreach ($redirects as $redirectlink) {
if('/thymus_vulgaris?tag=Oil&page=2' == $redirectlink['title']){
die;
}
}
如果我执行print_r($ redirects),则得到此数组结果,请参见下文
Array
(
[0] => Array
(
[title] => /thymus_vulgaris?tag=Oil&page=2
[url] => essential-oils
)
[1] => Array
(
[title] => /products/diffusers
[url] => diffusers
)
[2] => Array
(
[title] => /essential-oils/Essential-Oil-Kits/sleep_and_breathe
[url] => essential-oils
)
[3] => Array
(
[title] => /Solum%20Lux%20Telum
[url] => essential-oils
)
[4] => Array
(
[title] => /organic-boswellia-serrata
[url] => essential-oils
)
[5] => Array
(
[title] => /faqs
[url] => FAQ
)
[6] => Array
(
[title] => /clearance/refurbished-replacement-bottles/amp
[url] => accessories/bottles-and-caps/amp
)
[7] => Array
(
[title] => /refurbished-replacement-bottles/amp
[url] => accessories/bottles-and-caps/amp
)
)
如果看到第一个数组值与请求$ _SERVER ['REQUEST_URI']值相同。 有人可以快速帮助我吗?
答案 0 :(得分:1)
我猜可能是一些不可见的字符,因为==
产生了false
,
例如:DEMO
$ php -r '$f1="foo"; $f2="foo\0"; echo $f1.PHP_EOL; echo $f2.PHP_EOL; var_dump($f1); var_dump($f2); var_dump($f1==$f2);'
foo
foo
string(3) "foo"
string(4) "foo"
bool(false)
从上面可以看到,$f1
和$f2
并不相等,但是看起来一样。
输出: