i have the following regular expression:
$patterns = array
(
'/\b(gubalowka hegy)\b/i',
'/\b(krakkó|wawel|wawelban|auschwitz|auschwitzba|auschwitz-birkenua)\b/i',
'/\b(királyi|város|fogaskerekű|séta)\b/i',
);
$replaces = array
(
'<strong>$1</strong>',
'<u><em>$1</em></u>',
'<strong>$1</strong>',
);
preg_replace($patterns, $replaces, $text);
The problem is, that only some words gets replaced.
By this example only these words:
Séta => <strong>Séta</strong>
Krakkó => <u><em>Krakkó</em></u>
királyi => <strong>királyi</strong>
Auschwitz-Birkenua => <u><em>Auschwitz-Birkenua</em></u>
The other words stay untouched.
I tried to get it working several ways (replacing every word seperately, replacing group of words without arrays) but neither of them worked.
Here you can check it: http://adriaholiday.dev.webndev.hu/ajanlatok/lengyelorszagi-hetvege.html
The regular expressions get logged in chrome dev console
Could somebody help ? Thank you.
Edit:
If I write the regex, it works
$pattern = '/\b(krakkó|wawel|wawelban|auschwitz|auschwitzba)\b/iu'
$replace = '<strong><u>$1</u></strong>';
$text = preg_replace($pattern, $replace, $text);
the issue appears only when the regex gets generated
$replace = '<strong>$1</strong>';
foreach (...)
{
$words .= "|{$word}"; // first vertical bar removed ...
}
// encoding UTF8
// pattern: /\b(krakkó|wawel|wawelban|auschwitz|auschwitzba)\b/iu
$pattern = '/\b(' . $words . ')\b/iu';
$text = preg_replace($pattern, $replace, $text);
uto your modifiers (/foo/iu) to tell PCRE to treat the pattern as UTF-8. see php.net/manual/en/reference.pcre.pattern.modifiers.php