Frage

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.

War es hilfreich?

Lösung

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

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

Andere Tipps

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)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top