Question

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.

Was it helpful?

Solution

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

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

OTHER TIPS

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top