View Full Version : Strpos trouble

11-25-2007, 10:40 PM
I have been reading the documentation at PHP.net but I must be missing something. The following code is failing to find the $needle in the $hay.

$needle ='CNC';
$hay = 'CNC, Inspection';
echo $needle . ":".$hay.'<br />';
$pos = strpos($hay, needle);
if ($pos === false) $pos='not found';
echo 'result:'.$pos.'<br>';

No matter how I play with this it never find the string. What am I doing wrong here?


11-25-2007, 10:42 PM
Doh! I see it now. Might help to have the $ infront the needle. Sorry to bother you people.

11-25-2007, 10:43 PM
If you've copied and pasted this directly from your code then I think your problem is quite simple... its on this line

$pos = strpos($hay, needle);

You'll kick yourself when you spot it ;)