473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

locale fr_FR.utf8 and str_word_count()

Hello,

str_word_count() does not seem to work with locale "fr_FR.utf8".
The output of the following script is
string(10) "fr_FR.utf8" Array ( [0] =bi [1] =re )

I think, that "bière" should be recognized as word.

Here is the test-script:

<?
echo '<html><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head><body>';
var_dump(setlocale(LC_ALL, 'fr_FR.utf8'));
print_r(str_word_count('bière', 1));
echo '</body></html>';
?>

Could someone help please?
My PHP version is 5.1.2.

Greetings, Peter

--
email: pmrb at free.fr
http://pmrb.free.fr/contact/
Aug 30 '06 #1
4 5202
same problem with greek.

<?php

//the str varible is my name in greek

setlocale(LC_ALL, 'el_GR.utf8');
$str = "ÅõÜããåëïò ÌðáëÜóêáò";
print_r(str_word_count($str, 1));

?>
results:

Array ( )

---

any help ?

php 4.4.4

-ebal
Aug 30 '06 #2
"Peter Münster" <lo**@signature.invalidwrote in message
news:Pi*******************************@gaston.delt adore.bzh...
Hello,

str_word_count() does not seem to work with locale "fr_FR.utf8".
The output of the following script is
string(10) "fr_FR.utf8" Array ( [0] =bi [1] =re )

I think, that "bière" should be recognized as word.

Here is the test-script:

<?
echo '<html><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head><body>';
var_dump(setlocale(LC_ALL, 'fr_FR.utf8'));
print_r(str_word_count('bière', 1));
echo '</body></html>';
?>

Could someone help please?
My PHP version is 5.1.2.

That might be a multibyte-string related problem. If the string is encoded
using multibyte charset, such as utf-8, it could be the reason
str_word_count is confused. PHP has a library for multibyte-functionality
designed to overcome the problems created by multibyte-encoded strings.
See:
http://fi2.php.net/manual/en/ref.mbstring.php

Once you've installed multibyte library, you could try writing a regular
expression for counting the words and use it with the mb_ereg* functions.

It's very sad that handling multibyte strings is not as easy as it would be
with simple english charset, but on the bright side, at least there is some
sort of support for it with the multibyte function library.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Aug 30 '06 #3
On Wed, 30 Aug 2006, Kimmo Laine wrote:
That might be a multibyte-string related problem. If the string is encoded
using multibyte charset, such as utf-8, it could be the reason
str_word_count is confused.
Yes, you're right: I've just tried with fr_FR.iso885915 and it works.
Once you've installed multibyte library, you could try writing a regular
expression for counting the words and use it with the mb_ereg* functions.
Thanks for the hint. As a workaround I use already a regular expression to
get the words, but str_word_count() is still better than my solution:
str_word_count() detects constructs like "it's" and "week-end" etc.

Is multi-byte support planned for str_word_count() ?

Cheers, Peter

--
email: pmrb at free.fr
http://pmrb.free.fr/contact/
Aug 30 '06 #4
"Peter Münster" <lo**@signature.invalidwrote in message
news:Pi*****************************@gaston.deltad ore.bzh...
On Wed, 30 Aug 2006, Kimmo Laine wrote:
>That might be a multibyte-string related problem. If the string is
encoded
using multibyte charset, such as utf-8, it could be the reason
str_word_count is confused.

Yes, you're right: I've just tried with fr_FR.iso885915 and it works.
That's great. :)
>Once you've installed multibyte library, you could try writing a regular
expression for counting the words and use it with the mb_ereg* functions.

Thanks for the hint. As a workaround I use already a regular expression to
get the words, but str_word_count() is still better than my solution:
str_word_count() detects constructs like "it's" and "week-end" etc.
There were some examples of regexp substitutions for str_word_count in the
php.net manualpage, in the user contributions. You might want to check them.

For example rcATinterfacesDOTfr suggests that

$word_count = count(preg_split('/\W+/', $text, -1,
PREG_SPLIT_NO_EMPTY));

should work. The advantage in this solution is that there is mb_eregi_split
as well, wo you could use this with the mb-functions if you wanted to use
utf-8.

I try to enforce utf-8 whenever it is possible simply because of it's
advantages in an international multilingual communication even thou it has
it's disadvantages as well.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Aug 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Epler | last post by:
I'd expect these two to be identical, but they don't seem to be. >>> import locale >>> locale.setlocale(locale.LC_ALL, "fr_FR") 'fr_FR' >>> locale.nl_langinfo(locale.DAY_1) 'dimanche' >>> #...
2
by: Benoît Dejean | last post by:
here are my locales benoit@athlon >> locale LANG=fr_FR.UTF-8 LC_CTYPE="fr_FR.UTF-8" LC_NUMERIC="fr_FR.UTF-8" LC_TIME="fr_FR.UTF-8" LC_COLLATE="fr_FR.UTF-8" LC_MONETARY="fr_FR.UTF-8"
2
by: Peter Münster | last post by:
Hello, on page http://www.php.net/manual/en/function.str-word-count.php it's stated that: "For the purpose of this function, 'word' is defined as a locale dependent string" But it does not...
7
by: Ralf Goertz | last post by:
Hi, since my previous post <455440ad$0$30326$9b4e6d93@newsspool1.arcor-online.netis still unanswered I'd like to rephrase my question. In order to read/write a wstring in UTF-8 encoding it is...
2
by: Clodoaldo | last post by:
When using unicode the case change works: é But when using the pt_BR.utf-8 locale it doesn't: 'pt_BR.utf-8' ('pt_BR', 'utf') É
0
by: Thore Harald =?iso-8859-1?Q?H=F8ye?= | last post by:
I have made this testcase: ----------------------- #!/usr/bin/perl #use locale; #use encoding 'iso-8859-1'; use utf8; binmode(STDOUT, ":utf8"); print "\\x{00D8}:\n"; test("\x{00D8}");
24
by: Donn Ingle | last post by:
Hello, I hope someone can illuminate this situation for me. Here's the nutshell: 1. On start I call locale.setlocale(locale.LC_ALL,''), the getlocale. 2. If this returns "C" or anything...
0
by: Roman Bertle | last post by:
Hello, I try to format monetary values using the locale module, python2.5: Python 2.5.2a0 (r251:54863, Jan 3 2008, 17:59:56) on linux2 Type "help", "copyright", "credits" or "license" for...
2
by: koara | last post by:
Hello all, I needed to read contents of an UTF8 encoded file in C++ (gcc version 3.3.5 on Linux). I decided to do it the C++ way, using streams: ------------- std::locale...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.