...

View Full Version : Strpos trouble



Nightchild
11-25-2007, 09: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?

Thanks

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

NancyJ
11-25-2007, 09: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 ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum