redfox180 Posted January 22, 2008 Share Posted January 22, 2008 Hi, do you know how to get a 'true' result just when there is an exact match on the word searched? EX. substr('cash' 'ca') will result to 0 and not to false. Thanks James Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/ Share on other sites More sharing options...
redfox180 Posted January 22, 2008 Author Share Posted January 22, 2008 I meant strpos... Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446365 Share on other sites More sharing options...
resago Posted January 22, 2008 Share Posted January 22, 2008 you could use preg_match with /b Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446368 Share on other sites More sharing options...
redfox180 Posted January 22, 2008 Author Share Posted January 22, 2008 No, I mean in one entry when searching... Is there anything that I can put in front of $needle to say I just want an exact match?? Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446371 Share on other sites More sharing options...
rhodesa Posted January 22, 2008 Share Posted January 22, 2008 are you looking for something like strcmp() ? Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446375 Share on other sites More sharing options...
redfox180 Posted January 22, 2008 Author Share Posted January 22, 2008 not really...it doesnt solve the problm Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446380 Share on other sites More sharing options...
AndyB Posted January 22, 2008 Share Posted January 22, 2008 humour me, my crystal ball's broken. Give some very specific examples of things you want to match and things you don't want to match, and provide some context to what you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446402 Share on other sites More sharing options...
redfox180 Posted January 22, 2008 Author Share Posted January 22, 2008 let's say: given x=abcdef y=cd x=y false x!=y true if i set up a regular strpos, y being part of x will result to value 2. What i want is an absolute x and/or y, all in one statement. Any chance? Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446435 Share on other sites More sharing options...
roopurt18 Posted January 22, 2008 Share Posted January 22, 2008 let's say: given x=abcdef y=cd x=y false x!=y true The built in operators work fine for what you're describing thus far. $x = 'abcdef'; $y = 'cd'; if($x === $y){ echo 'true'; }else{ echo 'false'; } What i want is an absolute x and/or y, all in one statement. Any chance? Say what? Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446454 Share on other sites More sharing options...
redfox180 Posted January 22, 2008 Author Share Posted January 22, 2008 say: $fpym_res= 'CARL PAID BY CASH' $fop_cash=strpos($fpym_res, "CASH"); if ($fop_cash===FALSE) $pay_cash=""; else $pay_cash="CASH"; $fop_ca=strpos($fpym_res, CA); if ($fop_ca===FALSE) $pay_ca=""; else $pay_ca="CA"; $pay="$pay_cash$pay_ca; The result will be CACASH and not CASH. That's why I said if you know how to 'limit' the request to an exact match when searching for a word... Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446467 Share on other sites More sharing options...
roopurt18 Posted January 22, 2008 Share Posted January 22, 2008 In this case, you're better off explod()'ing the string into an array, trim()'ing each element, and then checking if the values you want to find exist. <?php $fpym_res= 'CARL PAID BY CASH'; $arr = explode(' ', $fpym_res); $arr = array_map('trim', $arr); if(in_array('CASH', $arr)){ echo 'cash'; }else if(in_array('CA', $arr)){ echo 'ca'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446474 Share on other sites More sharing options...
redfox180 Posted January 22, 2008 Author Share Posted January 22, 2008 That's better! It makes more sense too... I'll need to review Arrays in PHP Cheers James Quote Link to comment https://forums.phpfreaks.com/topic/87264-solved-exact-match/#findComment-446485 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.