Reputation: 89
I have looked everywhere for something like this. I can't see to get it to work. I'm trying to have a if statement if a string contains a colon AND a dash.
String example (true): "Visor - Color : Black" String example (false): "Water Bottle - Blue"
I have tried different variations of this but its still not working.
if (preg_match(':|-]*', $productName)) {
TRUE
} else {
FALSE
}
Any suggestions?
Upvotes: 0
Views: 525
Reputation: 36934
Without regex:
if (substr_count($productName, '-') === 1 && substr_count($productName, ':') === 1) {
// true
}
Upvotes: 1