简体   繁体   English

strpos不能按预期工作,我在做什么错?

[英]strpos not working as expected, what am i doing wrong?

I was attempting to follow the example on php.net for strpos() but it does not seem to be working as expected for me. 我试图按照php.net上的strpos()的示例进行操作 ,但它似乎没有按我的预期工作。 It keeps printing the else case "not here". 它将继续打印其他情况“不在这里”。

$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');
}

Note: dpm is a Drupal function that simply displays information in the messages region of a Drupal site. 注意:dpm是Drupal函数,仅在Drupal站点的消息区域中显示信息。 Think of it as an 'echo' or 'print' with styling attached to it. 可以将其视为带有样式的“回声”或“印刷”。

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

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

From the manual you have your arguments backwards: 在手册中,您的论点倒退了:

http://us2.php.net/manual/en/function.strpos.php http://us2.php.net/manual/zh/function.strpos.php

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

strpos($href,$search_wcm)

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

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