strpos($needle, $haystack) !== false 未返回预期结果

问题描述 投票:0回答:2

我试图按照 php.net 上的 示例进行

strpos()
但它似乎没有按我的预期工作。 它不断打印 else 情况“不在这里”。

$href = "[!--\$testUrl('testlink','754')--]";
dpm($href);
$search_wcm = 'testUrl';
$pos_wcm = strpos($search_wcm, $href);
if ($pos_wcm !== false) {
  dpm('here');
} else {
  dpm('not here');
}

注意:

dpm()
是一个 Drupal 功能,它仅在 Drupal 站点的消息区域中显示信息。 将其视为附有样式的“回声”或“印花”。

php strpos
2个回答
4
投票

顺序错误,第一个参数应该是要搜索的字符串

$pos_wcm = strpos($href, $search_wcm);

3
投票

从手册中你可以得到你的论点:

https://www.php.net/manual/en/function.strpos.php

mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )

strpos($href,$search_wcm)
© www.soinside.com 2019 - 2024. All rights reserved.