Bug #77777 [Opn]: str_word_count function for Chinese text
| From: | deng5765 at gmail dot com | Date: | Fri, 22 Mar 2019 13:25:15 +0000 |
| Subject: | Bug #77777 [Opn]: str_word_count function for Chinese text | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220130@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77777&edit=1
ID: 77777
User updated by: deng5765 at gmail dot com
Reported by: deng5765 at gmail dot com
Summary: str_word_count function for Chinese text
Status: Open
Type: Bug
Package: Strings related
Operating System: CentOS and MacOS
PHP Version: 7.3.3
Block user comment: N
Private report: N
New Comment:
both got:
bool(false)
Previous Comments:
------------------------------------------------------------------------
[2019-03-22 10:09:48] cmb@php.net
Please try on both architectures:
var_dump(ctype_alpha('æä¸æ¯é±¼æµè¯'));
------------------------------------------------------------------------
[2019-03-21 07:24:41] deng5765 at gmail dot com
I set the locale like
<?php
$locale = setlocale(LC_ALL, 'zh_CN.UTF-8');
$content = 'æä¸æ¯é±¼æµè¯';
echo 'Locale: ', $locale, "\n";
echo 'PHP OS: ', PHP_OS, "\n";
echo 'PHP Version: ', PHP_VERSION, "\n";
echo 'Word Count: ', str_word_count($content), "\n";
but I still got the different values:
Locale: zh_CN.UTF-8
PHP OS: Linux
PHP Version: 7.3.3
Word Count: 0
Locale: zh_CN.UTF-8
PHP OS: Darwin
PHP Version: 7.3.3
Word Count: 6
Is it normal?
------------------------------------------------------------------------
[2019-03-21 05:55:41] deng5765 at gmail dot com
Ah, sorry, didn't notice that part.
Mac:
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
CentOS:
LANG=en_US.utf-8
LC_CTYPE="en_US.utf-8"
LC_NUMERIC="en_US.utf-8"
LC_TIME="en_US.utf-8"
LC_COLLATE="en_US.utf-8"
LC_MONETARY="en_US.utf-8"
LC_MESSAGES="en_US.utf-8"
LC_PAPER="en_US.utf-8"
LC_NAME="en_US.utf-8"
LC_ADDRESS="en_US.utf-8"
LC_TELEPHONE="en_US.utf-8"
LC_MEASUREMENT="en_US.utf-8"
LC_IDENTIFICATION="en_US.utf-8"
LC_ALL=en_US.utf-8
------------------------------------------------------------------------
[2019-03-21 05:01:37] requinix@php.net
> Counts the number of words inside string.
> For the purpose of this function, 'word' is defined as a locale dependent string
> containing alphabetic characters,
> which also may contain, but not start with "'" and "-" characters.
What is your locale set to?
------------------------------------------------------------------------
[2019-03-21 04:52:22] deng5765 at gmail dot com
Description:
------------
Different behaviour of str_word_count function in different operating system(CentOS and MacOS) for
Chinese text.
It return 0 for pure Chinese text under CentOS. I tested PHP 7.1 and PHP 7.2, same issue.
Seems can't find any clue in doc.
Test script:
---------------
<?php
$content = 'æä¸æ¯é±¼æµè¯';
echo 'PHP OS: ', PHP_OS, "\n";
echo 'PHP Version: ', PHP_VERSION, "\n";
echo 'Word Count: ', str_word_count($content), "\n";
Expected result:
----------------
PHP OS: Darwin
PHP Version: 7.3.3
Word Count: 6
PHP OS: Linux
PHP Version: 7.3.3
Word Count: 6
Actual result:
--------------
PHP OS: Darwin
PHP Version: 7.3.3
Word Count: 6
PHP OS: Linux
PHP Version: 7.3.3
Word Count: 0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77777&edit=1