<bdo id='q92mY'></bdo><ul id='q92mY'></ul>
    1. <legend id='q92mY'><style id='q92mY'><dir id='q92mY'><q id='q92mY'></q></dir></style></legend>
      <i id='q92mY'><tr id='q92mY'><dt id='q92mY'><q id='q92mY'><span id='q92mY'><b id='q92mY'><form id='q92mY'><ins id='q92mY'></ins><ul id='q92mY'></ul><sub id='q92mY'></sub></form><legend id='q92mY'></legend><bdo id='q92mY'><pre id='q92mY'><center id='q92mY'></center></pre></bdo></b><th id='q92mY'></th></span></q></dt></tr></i><div id='q92mY'><tfoot id='q92mY'></tfoot><dl id='q92mY'><fieldset id='q92mY'></fieldset></dl></div>

      <tfoot id='q92mY'></tfoot>

      <small id='q92mY'></small><noframes id='q92mY'>

        str_word_count() 用于非拉丁词?

        时间:2023-07-16

        <small id='rUA18'></small><noframes id='rUA18'>

          <bdo id='rUA18'></bdo><ul id='rUA18'></ul>
          <tfoot id='rUA18'></tfoot>

          1. <legend id='rUA18'><style id='rUA18'><dir id='rUA18'><q id='rUA18'></q></dir></style></legend>
              <tbody id='rUA18'></tbody>

                • <i id='rUA18'><tr id='rUA18'><dt id='rUA18'><q id='rUA18'><span id='rUA18'><b id='rUA18'><form id='rUA18'><ins id='rUA18'></ins><ul id='rUA18'></ul><sub id='rUA18'></sub></form><legend id='rUA18'></legend><bdo id='rUA18'><pre id='rUA18'><center id='rUA18'></center></pre></bdo></b><th id='rUA18'></th></span></q></dt></tr></i><div id='rUA18'><tfoot id='rUA18'></tfoot><dl id='rUA18'><fieldset id='rUA18'></fieldset></dl></div>
                  本文介绍了str_word_count() 用于非拉丁词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试计算用非拉丁语言(保加利亚语)编写的变量中的单词数.但似乎 str_word_count() 没有计算非拉丁词.php文件的编码为UTF-8

                  im trying to count the number of words in variable written in non-latin language (Bulgarian). But it seems that str_word_count() is not counting non-latin words. The encoding of the php file is UTF-8

                  $str = "текст на кирилица";
                  echo 'Number of words: '.str_word_count($str);
                  //this returns 0
                  

                  推荐答案

                  您可以使用正则表达式:

                  You may do it with regex:

                  $str = "текст на кирилица";
                  echo 'Number of words: '.count(preg_split('/s+/', $str));
                  

                  这里我将单词定界符定义为空格字符.如果可能还有其他东西将被视为单词分隔符,您需要将其添加到您的正则表达式中.

                  here I'm defining word delimiter as space characters. If there may be something else that will be treated as word delimiter, you'll need to add it into your regex.

                  另外,请注意,由于在正则表达式中没有 utf 字符 (不在字符串中) - /u 修饰符不是必需的.但是如果你想要一些 utf 字符作为分隔符,你需要添加这个正则表达式修饰符.

                  Also, note, that since there's no utf characters in regex (not in string) - /u modifier isn't required. But if you'll want some utf characters to act as delimiter, you'll need to add this regex modifier.

                  更新:

                  如果您只想在文字中处理 西里尔文 字母,您可以使用:

                  If you want only cyrillic letters to be treated in words, you may use:

                  $str = "текст 
                  на 12453
                  кирилица";
                  echo 'Number of words: '.count(preg_split('/[^А-Яа-яЁё]+/u', $str));
                  

                  这篇关于str_word_count() 用于非拉丁词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何计算php文本语句中的空间 下一篇:FOUND_ROWS() 不断返回 0

                  相关文章

                • <tfoot id='sQZwT'></tfoot>
                    <bdo id='sQZwT'></bdo><ul id='sQZwT'></ul>

                • <small id='sQZwT'></small><noframes id='sQZwT'>

                  <legend id='sQZwT'><style id='sQZwT'><dir id='sQZwT'><q id='sQZwT'></q></dir></style></legend>
                    <i id='sQZwT'><tr id='sQZwT'><dt id='sQZwT'><q id='sQZwT'><span id='sQZwT'><b id='sQZwT'><form id='sQZwT'><ins id='sQZwT'></ins><ul id='sQZwT'></ul><sub id='sQZwT'></sub></form><legend id='sQZwT'></legend><bdo id='sQZwT'><pre id='sQZwT'><center id='sQZwT'></center></pre></bdo></b><th id='sQZwT'></th></span></q></dt></tr></i><div id='sQZwT'><tfoot id='sQZwT'></tfoot><dl id='sQZwT'><fieldset id='sQZwT'></fieldset></dl></div>