Bug #79238 [Opn->Nab]: preg_split returns weird results
| From: | requinix@php.net | Date: | Fri, 07 Feb 2020 08:00:11 +0000 |
| Subject: | Bug #79238 [Opn->Nab]: preg_split returns weird results | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225414@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79238&edit=1
ID: 79238
Updated by: requinix@php.net
Reported by: vuongvankhanh89 at gmail dot com
Summary: preg_split returns weird results
-Status: Open
+Status: Not a bug
Type: Bug
Package: PCRE related
Operating System: Ubuntu 18.04
PHP Version: 7.4.2
Block user comment: N
Private report: N
New Comment:
You must use UTF-8 mode when working with UTF-8 patterns or inputs. https://3v4l.org/lI7FX
Previous Comments:
------------------------------------------------------------------------
[2020-02-07 07:50:26] vuongvankhanh89 at gmail dot com
Description:
------------
Hi, today i created a pattern to separate text to an array.
Regex string is very simple:
preg_split('/\R| /m',
'ç¿¶èåè
èç¿¶èååå Xèèè')
it detects whitespace and linebreak as the separators and then converts string to array of strings.
in the exam above there is no whitespace or linebreak but result i got is an array with 2 elements.
array(2) {
[0]=>
string(11) "ç¿¶èå�"
[1]=>
string(28) "èç¿¶èååå Xèèè"
}
è
has been turned to a separator, it also becomes a weird charactor.
Kindly help! Thanks in advance.
Test script:
---------------
var_dump(preg_split('/\R| /m',
'ç¿¶èåè
èç¿¶èååå Xèèè'));
Expected result:
----------------
array(1) {
[0]=>
string(39)
"ç¿¶èåè
èç¿¶èååå Xèèè"
}
Actual result:
--------------
array(2) {
[0]=>
string(11) "ç¿¶èå�"
[1]=>
string(28) "èç¿¶èååå Xèèè"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79238&edit=1