Bug #79238 [NEW]: preg_split returns weird results

From: Date: Fri, 07 Feb 2020 07:50:27 +0000
Subject: Bug #79238 [NEW]: preg_split returns weird results
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225413@lists.php.net to get a copy of this message
From:             vuongvankhanh89 at gmail dot com
Operating system: Ubuntu 18.04
PHP version:      7.4.2
Package:          PCRE related
Bug Type:         Bug
Bug description:preg_split returns weird results 

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 bug report at https://bugs.php.net/bug.php?id=79238&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=79238&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=79238&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=79238&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=79238&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=79238&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=79238&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=79238&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=79238&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=79238&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=79238&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79238&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=79238&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=79238&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=79238&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=79238&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=79238&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=79238&r=mysqlcfg


Thread (2 messages)

« previous php.bugs (#225413) next »