I was attempting to follow the example on php.net for strpos() but it does not seem to be working as expected for me. 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. Think of it as an 'echo' or 'print' with styling attached to it.

有帮助吗?

解决方案

Wrong order, the first param should be the string to search in

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

其他提示

From the manual you have your arguments backwards:

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

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

strpos($href,$search_wcm)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top