mjurmann Posted December 26, 2007 Share Posted December 26, 2007 Hello, I'm trying to search a string for an exact match. The only problem is, when I use the following code, it is returning any entries that contain the search term, rather than only the exact matches. <?php if (stristr($rowCats, '3')) { echo "checked=\"checked\""; } else {}?> If someone searches for 31, any entry with "3", "1", or "31" are returned, instead of just returning the entry with "31". I'd greatly appreciate it if someone could give me a tip or point me in the right direction. I don't mind doing research, I just can't figure out what to use besides stristr, which obviously isn't working the way I'd like it to. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/83223-search-string-for-exact-match/ Share on other sites More sharing options...
redarrow Posted December 26, 2007 Share Posted December 26, 2007 tried trim to get rid of spaces Quote Link to comment https://forums.phpfreaks.com/topic/83223-search-string-for-exact-match/#findComment-423350 Share on other sites More sharing options...
mjurmann Posted December 26, 2007 Author Share Posted December 26, 2007 Does anyone know what he means by "try trim to get rid of spaces"? Quote Link to comment https://forums.phpfreaks.com/topic/83223-search-string-for-exact-match/#findComment-423464 Share on other sites More sharing options...
PHP_PhREEEk Posted December 26, 2007 Share Posted December 26, 2007 Not really.. but you are going to need to learn Regular Expressions to accomplish what you want. There is an entire Forum for REGEX within PHP to post these questions. They'll give you a hand learning some new tools for string searching. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83223-search-string-for-exact-match/#findComment-423468 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.