saint959 Posted April 16, 2007 Share Posted April 16, 2007 Hi, is it possible to have a if statement that checks if a variable is LIKE a string. basically what i need is, if ($var1 LIKE $string) { mysql query here"; } What would the syntax for the if statement be? Link to comment https://forums.phpfreaks.com/topic/47236-if-variable-like-value/ Share on other sites More sharing options...
Glyde Posted April 16, 2007 Share Posted April 16, 2007 Maybe strpos() or stripos()? Link to comment https://forums.phpfreaks.com/topic/47236-if-variable-like-value/#findComment-230358 Share on other sites More sharing options...
boo_lolly Posted April 16, 2007 Share Posted April 16, 2007 http://us2.php.net/operators.comparison Link to comment https://forums.phpfreaks.com/topic/47236-if-variable-like-value/#findComment-230415 Share on other sites More sharing options...
marmite Posted April 16, 2007 Share Posted April 16, 2007 I've found this quite useful: http://en.wikibooks.org/wiki/Programming:PHP:if_structure I haven't come across a LIKE param or an "in" (if x in ('a','b','c') with php. I've used multiple ORs (||). If you find a LIKE or an IN, please post it here - or better still, PM me! Link to comment https://forums.phpfreaks.com/topic/47236-if-variable-like-value/#findComment-230652 Share on other sites More sharing options...
per1os Posted April 16, 2007 Share Posted April 16, 2007 lol here is a solution for you: if (in($x, "a,b,c")) { // processing here } function in($var, $vars) { $vars = explode($vars, ","); if (is_array($vars)) { foreach ($vars as $chk) { if ($chk == $var) return true; } } return false; } When all else fails create your own solution. Link to comment https://forums.phpfreaks.com/topic/47236-if-variable-like-value/#findComment-230657 Share on other sites More sharing options...
Glyde Posted April 17, 2007 Share Posted April 17, 2007 Maybe like this? <?php if (in_array("mystring", array('somestring', 'another', 'mystring'))) { // Code here } ?> But I don't think that's what he was asking. Link to comment https://forums.phpfreaks.com/topic/47236-if-variable-like-value/#findComment-230889 Share on other sites More sharing options...
fert Posted April 17, 2007 Share Posted April 17, 2007 http://us.php.net/manual/en/function.similar-text.php Link to comment https://forums.phpfreaks.com/topic/47236-if-variable-like-value/#findComment-230903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.