Jump to content

[SOLVED] if description does not contain the following words


Presto-X

Recommended Posts

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"?

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')");
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.