madmega Posted May 9, 2012 Share Posted May 9, 2012 Hi, i am trying to write a part of script for google shopping export, and all i want is that in this line, everything that is 0 or smaller, the line "pre-order" krijgt and everything that is 1 or greater the line "in stock" This is what i've got now, but it doesn't work I removed the rest of the long code. $patterns = array(); $patterns[0] = '=<0'; $patterns[1] = '=>1'; $replacements = array(); $replacements[0] = 'vooraf bestellen'; $replacements[1] = 'op voorraad'; if(OPTIONS_TONEN_FEED_AVAILABILITY == 1) $output .= "~" . preg_replace($patterns, $replacements, $row->quantity); Quote Link to comment https://forums.phpfreaks.com/topic/262288-greater-than-or-equal-to-variable/ Share on other sites More sharing options...
cyberRobot Posted May 9, 2012 Share Posted May 9, 2012 I'm pretty sure that preg_replace doesn't work like that. To use a comparison operator, you could do something like: <?php //... if($row->quantity <= 0) { $output .= "~vooraf bestellen"; } elseif($row->quantity >= 1) { $output .= "~op voorraad"; } ?> Will there ever be values between 0 and 1? Quote Link to comment https://forums.phpfreaks.com/topic/262288-greater-than-or-equal-to-variable/#findComment-1344204 Share on other sites More sharing options...
madmega Posted May 9, 2012 Author Share Posted May 9, 2012 IT WORKED, your script did the trick...thank you !!! Quote Link to comment https://forums.phpfreaks.com/topic/262288-greater-than-or-equal-to-variable/#findComment-1344212 Share on other sites More sharing options...
cyberRobot Posted May 9, 2012 Share Posted May 9, 2012 IT WORKED, your script did the trick...thank you !!! Glad to hear. Note that since it sounds like $row->quantity will never be between 0 and 1, you could skip the second test: <?php //... if($row->quantity <= 0) { $output .= "~vooraf bestellen"; } else { $output .= "~op voorraad"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/262288-greater-than-or-equal-to-variable/#findComment-1344216 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.