PHP preg_replace with \s working different in windows?

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP preg_replace with \s working different in windows?

Postby Boboli » 05. August 2018 15:14

On linux (not xampp) the code working fine, but localhost on windows 10 xampp 7.2.7(7.2.1 too) I have trouble with unicode or german umlauts (ä ö ü).

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))
show now as result string(0) ""

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?
Boboli
 
Posts: 14
Joined: 05. August 2018 15:01
XAMPP version: 7.4.24
Operating System: Windows 11

Re: PHP preg_replace with \s working different in windows?

Postby Nobbie » 06. August 2018 10:15

If i remember correctly, this is a well known bug in a 32-bit environment. I have a very similar problem in my forum running with SMF, the PMs (private messages) are mailed to the users and in this email the text is empty, if there is an umlaut in that text. I could break down the problem to the same preg_replace bug. That forum runs in a 32bit Linux(!) environment, therefore i think its due to 32bit and not due to Windows. There is no known fix for that problem (i.e. change the system).
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: PHP preg_replace with \s working different in windows?

Postby Boboli » 06. August 2018 11:35

Ah, yes xampp for windows is 32 Bit and my online system is linux 64 Bit. Thanks for this hint.

Xampp for windows version 7.2.x not planning a 64 Bit version?
Boboli
 
Posts: 14
Joined: 05. August 2018 15:01
XAMPP version: 7.4.24
Operating System: Windows 11

Re: PHP preg_replace with \s working different in windows?

Postby Nobbie » 06. August 2018 11:56

Boboli wrote:Xampp for windows version 7.2.x not planning a 64 Bit version?


I dont think so.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 122 guests