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. 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. 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 =) 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). 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(); ... 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. Link to comment https://forums.phpfreaks.com/topic/222311-like-with-if-statements/#findComment-1150039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.