Presto-X Posted November 10, 2009 Share Posted November 10, 2009 Hello everyone, I am parsing a MS Excel (.xls) file and adding it's content to a mySQL database, so far to good, but what I want to do is if the column titled description does not contain these words "seedlings" or "discount" then add it to the database but if it does skip it and keep looping. Here is my code that I am trying to get working: if((!empty($description))or($available >0)and(!preg_match("/seedlings/i", $description))): mysql_query("INSERT INTO `availability` VALUES ('','$description','$available','$price')"); endif; I may not be using the right function for this "preg_match"? Link to comment https://forums.phpfreaks.com/topic/181043-solved-if-description-does-not-contain-the-following-words/ Share on other sites More sharing options...
MadTechie Posted November 10, 2009 Share Posted November 10, 2009 preg_match is a little over kill for this, i would use stripos for example (untested) // if description is not empty and available is greater than 0 and description does not contain seedlings or discount if(!empty($description) && $available >0 && stripos($description, 'seedlings') === false && stripos($description, 'discount') === false){ mysql_query("INSERT INTO `availability` VALUES ('','$description','$available','$price')"); } Link to comment https://forums.phpfreaks.com/topic/181043-solved-if-description-does-not-contain-the-following-words/#findComment-955270 Share on other sites More sharing options...
Presto-X Posted November 11, 2009 Author Share Posted November 11, 2009 Hey MadTechie, this works great, I was beating my head on the key board all afternoon, thanks so much! Link to comment https://forums.phpfreaks.com/topic/181043-solved-if-description-does-not-contain-the-following-words/#findComment-955330 Share on other sites More sharing options...
MadTechie Posted November 11, 2009 Share Posted November 11, 2009 cool, At least it will give your keyboard a rest from the beating! Link to comment https://forums.phpfreaks.com/topic/181043-solved-if-description-does-not-contain-the-following-words/#findComment-955331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.