문제

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