I'd go for a regex to match:
$regex = "/(^|,)".$prefixe."(,|$)/";
preg_match($regex,$allPrefixes);
- On beginning of string before a comma,
- between commas or
- after comma, at end of string
The above regex will match, for example, 07
but not 007
.
General knowledge, not applicable in this case:
If 007
is not likely to appear, or prefixe
is not likely to be a substring of any other prefixe
, then you can use strpos($allPrefixes, $prefixe) > -1
instead, which is quite more efficient.
However
wrapping the $allPrefixes
string between ,
and using strpos might be both efficient and accurate:
strpos(",".$allPrefixes.",", ",".$prefixe.",")
will match 07 but not 007