|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35110 bug with str_word_count
Submitted: 2005-11-05 11:19 UTC Modified: 2005-11-09 09:35 UTC
From: desss at yandex dot ru Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.0.5 OS: winXP,Linux
Private report: No CVE-ID: None
 [2005-11-05 11:19 UTC] desss at yandex dot ru

setlocale(LC_ALL, 'ru_RU');
echo str_word_count("??????");

Result - 2 !!! Wrong!

That is because function understanding letter "?" as whitespace. 

Reproduce code:
setlocale(LC_ALL, 'ru_RU');
echo str_word_count("??????");

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-08 11:55 UTC]
1) there is no ru_RU locale on Win32.
2) it can be missing on Linux too.

So check the setlocale() result first (use var_dump(setlocale()) for that).
 [2005-11-09 08:40 UTC] desss at yandex dot ru
yes...for Win32 need to write "setlocale(LC_ALL, 'rus_RUS');". echo var_dump(setlocale(LC_ALL, 'rus_RUS')); return "string(19) "Russian_Russia.1251". (on Linux  - "string(5) "ru_RU".)
 [2005-11-09 08:44 UTC]
So it *does* work, right ?
 [2005-11-09 08:56 UTC] desss at yandex dot ru
No. Result is 2. Not 1.
 [2005-11-09 09:18 UTC]
Can't reproduce on Linux with ru_RU.koi8r locale.
PHP just uses isalpha() and other system functions to differentiate space chars from the others, so if it doesn't work for you - it's your system fault or you're doing something wrong.
 [2005-11-09 09:35 UTC] desss at yandex dot ru
hmm...on my linux now utf-8 rus locale... it's so strange...
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 25 07:01:31 2024 UTC