Welcome Guest, Not a member yet? Register   Sign In
find a string...
#4

[eluser]WanWizard[/eluser]
Don't know which PHP you're using, but here your example returns FALSE.

With strpos() you have to be careful anyway, because strpos('this is a string', 'this') returns 0 (zero), not FALSE. The best way to deal with this is:
Code:
$haystack='This is a red car';
$needle='green car';
$check = strpos($haystack, $needle);

if (  $check===FALSE )
{
    echo 'Not found';
}
else
{
    echo 'Found';
}


Messages In This Thread
find a string... - by El Forum - 05-16-2010, 08:24 AM
find a string... - by El Forum - 05-16-2010, 10:26 AM
find a string... - by El Forum - 05-16-2010, 11:01 AM
find a string... - by El Forum - 05-16-2010, 01:20 PM
find a string... - by El Forum - 05-16-2010, 01:32 PM
find a string... - by El Forum - 05-16-2010, 05:18 PM
find a string... - by El Forum - 05-16-2010, 11:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB