久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    • <bdo id='X9tBI'></bdo><ul id='X9tBI'></ul>

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

        使用 PHP 將字符串分成兩半(字識別)

        Split Strings in Half (Word-Aware) with PHP(使用 PHP 將字符串分成兩半(字識別))

          <bdo id='2vqNG'></bdo><ul id='2vqNG'></ul>
          <tfoot id='2vqNG'></tfoot>
        • <small id='2vqNG'></small><noframes id='2vqNG'>

          <i id='2vqNG'><tr id='2vqNG'><dt id='2vqNG'><q id='2vqNG'><span id='2vqNG'><b id='2vqNG'><form id='2vqNG'><ins id='2vqNG'></ins><ul id='2vqNG'></ul><sub id='2vqNG'></sub></form><legend id='2vqNG'></legend><bdo id='2vqNG'><pre id='2vqNG'><center id='2vqNG'></center></pre></bdo></b><th id='2vqNG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2vqNG'><tfoot id='2vqNG'></tfoot><dl id='2vqNG'><fieldset id='2vqNG'></fieldset></dl></div>

        • <legend id='2vqNG'><style id='2vqNG'><dir id='2vqNG'><q id='2vqNG'></q></dir></style></legend>
              <tbody id='2vqNG'></tbody>

                • 本文介紹了使用 PHP 將字符串分成兩半(字識別)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試將字符串分成兩半,它不應該在單詞中間分開.

                  I'm trying to split strings in half, and it should not split in the middle of a word.

                  到目前為止,我想出了以下 99% 的工作:

                  So far I came up with the following which is 99% working :

                  $text = "The Quick : Brown Fox Jumped Over The Lazy / Dog";
                  $half = (int)ceil(count($words = str_word_count($text, 1)) / 2); 
                  $string1 = implode(' ', array_slice($words, 0, $half));
                  $string2 = implode(' ', array_slice($words, $half));
                  

                  這確實有效,根據字符串中的單詞數將任何字符串正確地分成兩半.但是,它正在刪除字符串中的任何符號,例如對于上面的示例,它將輸出:

                  This does work, correctly splitting any string in half according to the number of words in the string. However, it is removing any symbols in the string, for example for the above example it would output :

                  The Quick Brown Fox Jumped
                  Over The Lazy Dog
                  

                  我需要在拆分后保留字符串中的所有符號,例如 : 和/.我不明白為什么當前的代碼要刪除符號...如果您能提供替代方法或修復此方法以不刪除符號,將不勝感激:)

                  I need to keep all the symbols like : and / in the string after being split. I don't understand why the current code is removing the symbols... If you can provide an alternative method or fix this method to not remove symbols, it would be greatly appreciated :)

                  推薦答案

                  在查看您的示例輸出時,我注意到我們所有的示例都關閉了,如果字符串的中間在一個單詞內,我們將減少給 string1然后給予更多.

                  Upon looking at your example output, I noticed all our examples are off, we're giving less to string1 if the middle of the string is inside a word rather then giving more.

                  例如The Quick : Brown Fox Jumped Over The Lazy/Dog的中間是The Quick : Brown Fox Ju,它在一個詞的中間,這個第一個示例為 string2 提供了拆分詞;下面的例子給出了 string1 的分割詞.

                  For example the middle of The Quick : Brown Fox Jumped Over The Lazy / Dog is The Quick : Brown Fox Ju which is in the middle of a word, this first example gives string2 the split word; the bottom example gives string1 the split word.

                  在拆分詞上給 string1 少

                  $text = "The Quick : Brown Fox Jumped Over The Lazy / Dog";
                  
                  $middle = strrpos(substr($text, 0, floor(strlen($text) / 2)), ' ') + 1;
                  
                  $string1 = substr($text, 0, $middle);  // "The Quick : Brown Fox "
                  $string2 = substr($text, $middle);  // "Jumped Over The Lazy / Dog"
                  

                  在拆分詞上給 string1 更多

                  $text = "The Quick : Brown Fox Jumped Over The Lazy / Dog";
                  
                  $splitstring1 = substr($text, 0, floor(strlen($text) / 2));
                  $splitstring2 = substr($text, floor(strlen($text) / 2));
                  
                  if (substr($splitstring1, 0, -1) != ' ' AND substr($splitstring2, 0, 1) != ' ')
                  {
                      $middle = strlen($splitstring1) + strpos($splitstring2, ' ') + 1;
                  }
                  else
                  {
                      $middle = strrpos(substr($text, 0, floor(strlen($text) / 2)), ' ') + 1;    
                  }
                  
                  $string1 = substr($text, 0, $middle);  // "The Quick : Brown Fox Jumped "
                  $string2 = substr($text, $middle);  // "Over The Lazy / Dog"
                  

                  這篇關于使用 PHP 將字符串分成兩半(字識別)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                    <i id='HFs5Q'><tr id='HFs5Q'><dt id='HFs5Q'><q id='HFs5Q'><span id='HFs5Q'><b id='HFs5Q'><form id='HFs5Q'><ins id='HFs5Q'></ins><ul id='HFs5Q'></ul><sub id='HFs5Q'></sub></form><legend id='HFs5Q'></legend><bdo id='HFs5Q'><pre id='HFs5Q'><center id='HFs5Q'></center></pre></bdo></b><th id='HFs5Q'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HFs5Q'><tfoot id='HFs5Q'></tfoot><dl id='HFs5Q'><fieldset id='HFs5Q'></fieldset></dl></div>

                      <tbody id='HFs5Q'></tbody>
                      • <bdo id='HFs5Q'></bdo><ul id='HFs5Q'></ul>
                          <legend id='HFs5Q'><style id='HFs5Q'><dir id='HFs5Q'><q id='HFs5Q'></q></dir></style></legend><tfoot id='HFs5Q'></tfoot>

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

                            主站蜘蛛池模板: 视频一区二区三区中文字幕 | 久久机热| 亚洲视频网 | 91天堂| 一区二区三区四区视频 | 久久久久久免费毛片精品 | 一级大黄色片 | 国产欧美久久精品 | 在线欧美日韩 | 亚洲国产第一页 | 在线日韩不卡 | 五月免费视频 | 国产精品一卡 | 羞视频在线观看 | av色站 | 在线播放一区二区三区 | 日韩欧美在线观看 | 欧美日韩久久久久 | 欧美一级欧美三级在线观看 | 欧美最猛黑人 | 中文字幕在线观看第一页 | 国产成人免费 | 色av一区二区三区 | 亚洲国产成人精品久久 | 精品国产免费一区二区三区演员表 | 国产精品亚洲一区二区三区在线 | h视频免费观看 | 自拍偷拍第1页 | 欧美一级久久 | 91久久久久久 | 在线观看a视频 | 日韩精品视频在线 | 久久久久久久久91 | 日本精品视频在线观看 | 日日摸日日爽 | 欧美另类视频 | 国产日韩中文字幕 | 美女视频黄色片 | 久久亚洲一区二区三区四区 | 亚洲不卡在线观看 | 香蕉一区|