locale fr_FR.utf8 and str_word_count()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Münster

    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(setloc ale(LC_ALL, 'fr_FR.utf8'));
    print_r(str_wor d_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
    Peter Münster *** Brittany *** France

  • Balaskas Evaggelos

    #2
    Re: locale fr_FR.utf8 and str_word_count( )

    same problem with greek.

    <?php

    //the str varible is my name in greek

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

    ?>


    results:

    Array ( )

    ---

    any help ?

    php 4.4.4

    -ebal

    Comment

    • Kimmo Laine

      #3
      Re: locale fr_FR.utf8 and str_word_count( )

      "Peter Münster" <look@signature .invalidwrote in message
      news:Pine.LNX.4 .64.06083008062 40.28934@gaston .deltadore.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(setloc ale(LC_ALL, 'fr_FR.utf8'));
      print_r(str_wor d_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:


      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
      spam@outolempi. net || Gedoon-S @ IRCnet || rot13(xvzzb@bhg byrzcv.arg)


      Comment

      • Peter Münster

        #4
        Re: locale fr_FR.utf8 and str_word_count( )

        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
        Peter Münster *** Brittany *** France

        Comment

        • Kimmo Laine

          #5
          Re: locale fr_FR.utf8 and str_word_count( )

          "Peter Münster" <look@signature .invalidwrote in message
          news:Pine.LNX.4 .64.06083014004 00.871@gaston.d eltadore.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_cou nt 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 rcATinterfacesD OTfr suggests that

          $word_count = count(preg_spli t('/\W+/', $text, -1,
          PREG_SPLIT_NO_E MPTY));

          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
          spam@outolempi. net || Gedoon-S @ IRCnet || rot13(xvzzb@bhg byrzcv.arg)


          Comment

          Working...