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

[eluser]outtolunch[/eluser]
Hello guys,

I'm trying to find a string in the other string. I've used strpos and preg_match, it works fine, but there is one problem.

For example:

Code:
$haystack='This is a red car';
$needle='green car';
$check = strpos($haystack, $needle);

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

it will return true, as it found "car" in the string, but i don't want that, as it really should look for "green car" and as it's red, should return "false". The same thing is with preg_match, I've tried them both and experimented a bit.

Any suggestions of how to look for exact string within the other string? That would be very helpful, thanks!


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