phorcon3 Posted May 8, 2008 Share Posted May 8, 2008 <?php $test = 'Online Store'; if(ereg('Store',$test)) { echo 'yes'; } else { echo 'no'; } ?> this should actually display no.. because i want it to be an exact result.. how can i do this? ereg obviously doesnt do the trick:( Quote Link to comment https://forums.phpfreaks.com/topic/104723-exact-search/ Share on other sites More sharing options...
Rohan Shenoy Posted May 8, 2008 Share Posted May 8, 2008 $search_term="rohan"; $string="rohan shenoy was here"; if($search_term==$string) {echo "match found";} else {echo "Match not found";} Hope this is the way you expected it. ereg or preg functions are not for this purpose anywayz! You can try using strpos() too if you find occurrence of an exact phrase within a string. Quote Link to comment https://forums.phpfreaks.com/topic/104723-exact-search/#findComment-535998 Share on other sites More sharing options...
sasa Posted May 8, 2008 Share Posted May 8, 2008 <?php $test = 'Online Store'; if(ereg('^Store$',$test)) { echo 'yes'; } else { echo 'no'; } ?> or just <?php $test = 'Online Store'; if($test == 'Store') { echo 'yes'; } else { echo 'no'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104723-exact-search/#findComment-536002 Share on other sites More sharing options...
Fadion Posted May 8, 2008 Share Posted May 8, 2008 Why compile a regular expression for such a basic task?! The equality operator works just fine. Quote Link to comment https://forums.phpfreaks.com/topic/104723-exact-search/#findComment-536003 Share on other sites More sharing options...
discomatt Posted May 8, 2008 Share Posted May 8, 2008 To do it with regex you'd want this preg_match('/^Store$/',$test) But the above method is faster Quote Link to comment https://forums.phpfreaks.com/topic/104723-exact-search/#findComment-536024 Share on other sites More sharing options...
phorcon3 Posted May 8, 2008 Author Share Posted May 8, 2008 i have to use regex b/c im runnin arrays and its lookin for a perfect match? i guess.... ...thanks sasa ...that does it;) Quote Link to comment https://forums.phpfreaks.com/topic/104723-exact-search/#findComment-536109 Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 ( equals would do the same thing. ) Quote Link to comment https://forums.phpfreaks.com/topic/104723-exact-search/#findComment-536117 Share on other sites More sharing options...
Fadion Posted May 9, 2008 Share Posted May 9, 2008 i have to use regex b/c im runnin arrays and its lookin for a perfect match? i guess.... ...thanks sasa ...that does it;) Why does it have to matter if its an array or not: <?php $arr = array('php', 'mysql', 'html'); foreach($arr as $val){ if($arr == 'php'){ echo 'My array has got php in it.'; } } ?> or even better <?php $arr = array('php', 'mysql', 'html'); if(in_array('php', $arr)){ echo 'My array has got php in it.'; } ?> It is looking for a perfect match in an array. Whats the deal with regex then!!! Quote Link to comment https://forums.phpfreaks.com/topic/104723-exact-search/#findComment-536482 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.