我试图按照 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 站点的消息区域中显示信息。 将其视为附有样式的“回声”或“印花”。
顺序错误,第一个参数应该是要搜索的字符串
$pos_wcm = strpos($href, $search_wcm);
从手册中你可以得到你的论点:
https://www.php.net/manual/en/function.strpos.php
mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
strpos($href,$search_wcm)