<bdo id='OmD4f'></bdo><ul id='OmD4f'></ul>
    1. <small id='OmD4f'></small><noframes id='OmD4f'>

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

        使用 PHP 正则表达式匹配字符串中的任何 Unicode

        时间:2023-10-03

              <tbody id='uSxdW'></tbody>
            • <tfoot id='uSxdW'></tfoot>

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

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

                  本文介绍了使用 PHP 正则表达式匹配字符串中的任何 Unicode 空白字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在每个空间将文本消息拆分成数组.在我收到这条短信之前,它一直工作得很好.下面是处理文本字符串的几行代码:

                  I want to split text message into array at every Space. It's been working just fine until I received this text message. Here is the few code lines that process the text string:

                      $str = 'T bw4  05/09/19 07:51 am BW6N 499.803';
                      $cleanStr = iconv("UTF-8", "ISO-8859-1", $str);
                      $strArr = preg_split('/[s	]/', $cleanStr);
                      var_dump($strArr);
                  

                  Var_dump 产生这个结果:

                  Var_dump yields this result:

                  array:6 [▼
                   0 => "T"
                   1 => b"bw4  05/09/19"
                   2 => "07:51"
                   3 => "am"
                   4 => "BW6N"
                   5 => "499.803"
                  ]
                  

                  数组 "1 => b"bw4 05/09/19"" 中的 #1 项不正确,我无法弄清楚数组值前面的字母 "b" 是什么.此外,bw4"和05/09/19"之间的空格非常感谢有关如何更好地实现字符串拆分的任何建议.这是原始字符串:https://3v4l.org/2L35M,这是我的结果图像本地主机:http://prntscr.com/jjbvny

                  The #1 item in the array "1 => b"bw4 05/09/19"" in not correct, I am not able figure out what is the letter "b" in front of the array value. Also, the space(es) between "bw4" and "05/09/19" Any suggestion on how better achieve the string splitting are greatly appreciated. Here is the original string: https://3v4l.org/2L35M and here is the image of result from my localhost: http://prntscr.com/jjbvny

                  推荐答案

                  要匹配您可能使用的任何 1 个或多个 Unicode 空白字符

                  To match any 1 or more Unicode whitespace chars you may use

                  '~s+~u'
                  

                  您的 '/[s ]/' 模式仅匹配单个空白字符 (s) 或制表符 ( )(这当然是多余的,因为 s 也已经匹配制表符了),但是由于缺少 u 修饰符,s 无法匹配 bw4 之后的 u00A0 字符(硬空格).

                  Your '/[s ]/' pattern only matches a single whitespace char (s) or a tab ( ) (which is of course redundant as s already matches tabs, too), but since the u modifier is missing, the s cannot match the u00A0 chars (hard spaces) you have after bw4.

                  所以,使用

                  $str = 'T bw4  05/09/19 07:51 am BW6N 499.803';
                  $strArr = preg_split('/s+/u', $str);
                  print_r($strArr);
                  

                  查看 PHP 演示 产出

                  Array
                  (
                      [0] => T
                      [1] => bw4
                      [2] => 05/09/19
                      [3] => 07:51
                      [4] => am
                      [5] => BW6N
                      [6] => 499.803
                  )
                  

                  这篇关于使用 PHP 正则表达式匹配字符串中的任何 Unicode 空白字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP 和 RegEx:用不在括号内(以及嵌套括号)的逗号分 下一篇:如何将段落拆分为句子

                  相关文章

                  最新文章

                    <bdo id='H6Pun'></bdo><ul id='H6Pun'></ul>

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

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

                  2. <tfoot id='H6Pun'></tfoot>
                  3. <legend id='H6Pun'><style id='H6Pun'><dir id='H6Pun'><q id='H6Pun'></q></dir></style></legend>