- Code: Select all
$text = 'a Ž b c d e';
Output working fine:
- Code: Select all
echo htmlspecialchars($text, ENT_QUOTES, 'UTF-8', TRUE);
Now I want replace spaces with a single underscore.
- Code: Select all
$text = preg_replace('/\s\s+/', '_', $text);
Output with echo $text show me
- Code: Select all
a_�_b_c_d e
The second character is now unknown. Output with
- Code: Select all
var_dump(htmlspecialchars($text, ENT_QUOTES, 'UTF-8', TRUE))
Add modifier u to preg_replace('/\s\s+/u', '_', $text) the result is correct with string(12) "a_Ž b_c_d e".
In Linux its working without modifier u. https://regex101.com/r/sNIxdn/1/
When I use instead \s only a space and without modifier u: preg_replace('/ +/', '_', $text) its working too on windows 10. But this replace all spaces, not only minimum two spaces.
What is the issue with preg_replace() and \s on windows with unicode and umlauts?