Jerred121 Posted February 1, 2011 Share Posted February 1, 2011 I'm pretty sure there isn't, but I was wondering if there was a php function that would return partial matches similar to MySQL's LIKE, I've been searching for a while and haven't found one. If not, is there a class or something that someone knows of that will accomplish a like of search or a string comparison? I want to be able to compare two variables and return one of three results - Exact Match, Partial Match, No Match. I suppose regex may do the trick but I'm a complete novice when it comes to regex and I have no idea where to even begin. Thanks for any suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/226390-php-function-similar-to-mysql-like/ Share on other sites More sharing options...
Maq Posted February 1, 2011 Share Posted February 1, 2011 Depending on how strict you want your matches to be it sounds like you should be using preg_match. Quote Link to comment https://forums.phpfreaks.com/topic/226390-php-function-similar-to-mysql-like/#findComment-1168504 Share on other sites More sharing options...
AbraCadaver Posted February 1, 2011 Share Posted February 1, 2011 There is preg_match() as Maq proposed, but easier is strpos() to test if a string is in another string. Quote Link to comment https://forums.phpfreaks.com/topic/226390-php-function-similar-to-mysql-like/#findComment-1168520 Share on other sites More sharing options...
MatthewJ Posted February 1, 2011 Share Posted February 1, 2011 I'd start with a tutorial on regex... it is not that hard to get your hand around when you sit down and power through it. Just don't try and remember every character etc.. look them up and focus on what the regex functions themselves are doing. It is usually pretty easy to find a pattern that is close and manipulate it to what you need. Quote Link to comment https://forums.phpfreaks.com/topic/226390-php-function-similar-to-mysql-like/#findComment-1168543 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.