I am trying to use regular expressions to make my inventory upload script a little better.
I sell clothing and accessories. In my inventory file I have a field called ProductDepartment which is a combination of gender/item type. I have a MySQL table for gender with the following values:
Mens = 1 Womens = 2 Unisex = 3
Departments in the uploaded file look like the following, for example.
Mens Outerwear Mens Watches Womens Jeans Headphones
So basically Im trying to make a statment that goes, if $ProductDept contains Mens, set $gender_id = 1, if $ProductDept contains Womens, set $gender_id = 2, if $ProductDept does not contain either, set $gender_id = 3
And I'm having trouble figuring out how to write the 3rd if statement correctly. Here's what I have.
if(preg_match('/Mens/g', $ProductDept)) {
$gender_id = '1';
}
if(preg_match('/Womens/g', $ProductDept)) {
$gender_id = '2';
}
if( != preg_match('/Mens|Womens/g', $ProductDept)) {
$gender_id = '3';
}