how do i compare php string vars using regex -
i match (with regex) 2 strings ignoring fact 1 string may or may not have hyphens and/or single-quote chars (in fact ignore punctuation in both strings).
the problem both strings within php variables, not literals can however, not variables - ideas please ... possible.
for example pattern modifier /i specifies case-insensitive comparisons - there modifier ignore punctuation compare alpha-numeric strings ??
if (preg_replace("/['\-]/", '', $str1) == preg_replace("/['\-]/", '', $str2) { ...equal... }
basically: strip out '
, -
both strings, compare resulting stripped strings. if yout want case-insensitive, strtolower(preg_replace(....))
instead.
Comments
Post a Comment