php strrpos 检测不到字符串,始终为0位置
大家好,这真是一个令人惊叹的问题。
我对 strrpos 有很多经验,但这确实没有意义。首先是数组:
arrCopy => {
["Codice"]=>
string(33) "Per sport d è numerico"
["Maniche"]=>
string(15) " maniche corte "
...
["Taglia"]=>
string(8) "tg tg XL"
}
我想在 Foreach 循环中隔离“Taglia”的行为,但我无法检测到它!
foreach ($arrCopy as $key=>$spec){
echo gettype($key); // prints string
$tg= strpos(strtolower($key) , 'taglia'); // gives me
//always 0 also with "Taglia" key
if ( $tg !== false || ....
// never goes there
我哪里错了?
Hi guys this is really stunning questions.
I have many experience with strrpos but this is really out of sense . First the array:
arrCopy => {
["Codice"]=>
string(33) "Per sport d è numerico"
["Maniche"]=>
string(15) " maniche corte "
...
["Taglia"]=>
string(8) "tg tg XL"
}
I want to isolate behaviour of "Taglia" in a Foreach loop, but I cannot detect it!
foreach ($arrCopy as $key=>$spec){
echo gettype($key); // prints string
$tg= strpos(strtolower($key) , 'taglia'); // gives me
//always 0 also with "Taglia" key
if ( $tg !== false || ....
// never goes there
Where I am wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该测试 strpos() 的 retval 是否为 FALSE,以确定是否包含该字符串。
来自 http://php.net/manual/en/function.strpos.php:
使用 strcmp 可能会更好 - 您不需要太多地尝试查找子字符串,而是确保匹配。
You should test the retval of strpos() against FALSE, to determine whether the string is contained.
From http://php.net/manual/en/function.strpos.php:
Probably better to use strcmp - you're not so much trying to find a substring, as to ensure a match.