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

[eluser]vitoco[/eluser]
[quote author="outtolunch" date="1274056334"]The thing is, that it first checks car and then red car, they both will return true, but i still need red car.

Thanks for your reply Smile[/quote]

strpos is a short for "string position", so it doesn't return true or false in case that the "needle" string it's found in the "haystack" string, it only returns the position (int) of the needle in the haystack. so the value goes from 0 ( zero) to strlen( $haystack) - 1 .

the correct way
Code:
$haystack = 'This is a red car';
$needle   = 'green car';
$position = strpos( $haystack , $needle );

// POSITION INT 0....N-1
if( $position !== false )
{
    echo 'Found';
}
// POSITION FALSE
else
{
    echo 'Not found';
}

Saludos


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