I have a code that detects a semi-column in a string and executes a function
if (ereg(";",$str)) { $myfunction($abc); }
I'd like to expand this functionality to do the same if the string contains more than 2 commas or the word "and".
Stuck. 😕
Use [man]substr_count/man?
Something like this?
if ( ereg(";",$str) || ereg(" and ",$str) || substr_count($str, ',') > 2 ) { $myfunction($abc); }
Kind of awkward..
:bemused:
I would prefer strpos() to ereg() in this case:
if (strpos($str, ';') !== false || strpos($str, ' and ') !== false || substr_count($str, ',') > 2) { $myfunction($abc); }
Awkward, yes, but that's inherent in what you want to do.