soltek Posted December 21, 2010 Share Posted December 21, 2010 Hey guys, is there any way to have a LIKE condition on an IF statement? Something like: if $GET_['WTV'] LIKE %LOVE% { $category=romance Any clues? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/222311-like-with-if-statements/ Share on other sites More sharing options...
Maq Posted December 21, 2010 Share Posted December 21, 2010 Hey guys, is there any way to have a LIKE condition on an IF statement? Something like: if $GET_['WTV'] LIKE %LOVE% { $category=romance Any clues? Thanks in advance. You can use preg_match. The syntax you're using is SQL. Quote Link to comment https://forums.phpfreaks.com/topic/222311-like-with-if-statements/#findComment-1149959 Share on other sites More sharing options...
soltek Posted December 21, 2010 Author Share Posted December 21, 2010 Hey guys, is there any way to have a LIKE condition on an IF statement? Something like: if $GET_['WTV'] LIKE %LOVE% { $category=romance Any clues? Thanks in advance. You can use preg_match. The syntax you're using is SQL. Damn, it sucks to be a noob. Thanks for your help. Have a nice christmas =) Quote Link to comment https://forums.phpfreaks.com/topic/222311-like-with-if-statements/#findComment-1149965 Share on other sites More sharing options...
requinix Posted December 21, 2010 Share Posted December 21, 2010 Regular expressions are overkill for just looking in a string. SQL's LIKE is akin to PHP's stripos (or strpos(), depending). Quote Link to comment https://forums.phpfreaks.com/topic/222311-like-with-if-statements/#findComment-1149967 Share on other sites More sharing options...
The Letter E Posted December 21, 2010 Share Posted December 21, 2010 lets not forget about strstr(); ... Quote Link to comment https://forums.phpfreaks.com/topic/222311-like-with-if-statements/#findComment-1150028 Share on other sites More sharing options...
Maq Posted December 21, 2010 Share Posted December 21, 2010 lets not forget about strstr(); ... In this particular instance strpos would be the fastest. You're right requinix, there's no need for regex here. Quote Link to comment https://forums.phpfreaks.com/topic/222311-like-with-if-statements/#findComment-1150039 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.