I always get 'A match was found.' What am I doing wrong?
I really just want to match distinct words. I should actually get a 'A match was NOT found.', but I don't.
"Meller Str. 33 · 49082 Osnabrueck"
->should match
"Meller Str. 33 · 49082 Osnabrueck"
->should match
"Meller Str. 33 · 490821 Osnabrueck"
->should not match
Probably a small mistake with a big impact...
Code: Select all
$arrDaten['Plz'] = '49082';
$arrDaten['Ort'] = 'Osnabrueck';
/* The \b in the pattern indicates a word boundary, so only the distinct
* word "web" is matched, and not a word partial like "webbing" or "cobweb" */
$pattern = "'|\b".preg_quote($arrDaten['Plz'])."\b\s+\b".preg_quote($arrDaten['Ort'])."\b|i'";
$value = "Meller Str. 33 · 490821 Osnabrueck";
echo $pattern;
if (preg_match( $pattern, $value))
{
echo "A match was found.";
}
else
{
echo "A match was NOT found.";
}