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

    • <bdo id='26rnK'></bdo><ul id='26rnK'></ul>

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

        <legend id='26rnK'><style id='26rnK'><dir id='26rnK'><q id='26rnK'></q></dir></style></legend>
      1. <tfoot id='26rnK'></tfoot>

        <small id='26rnK'></small><noframes id='26rnK'>

        確保 PHP 中的有效 UTF-8

        Ensuring valid UTF-8 in PHP(確保 PHP 中的有效 UTF-8)

          <tbody id='kd5sQ'></tbody>
        <tfoot id='kd5sQ'></tfoot>

          1. <small id='kd5sQ'></small><noframes id='kd5sQ'>

              <bdo id='kd5sQ'></bdo><ul id='kd5sQ'></ul>
              • <legend id='kd5sQ'><style id='kd5sQ'><dir id='kd5sQ'><q id='kd5sQ'></q></dir></style></legend>
                  <i id='kd5sQ'><tr id='kd5sQ'><dt id='kd5sQ'><q id='kd5sQ'><span id='kd5sQ'><b id='kd5sQ'><form id='kd5sQ'><ins id='kd5sQ'></ins><ul id='kd5sQ'></ul><sub id='kd5sQ'></sub></form><legend id='kd5sQ'></legend><bdo id='kd5sQ'><pre id='kd5sQ'><center id='kd5sQ'></center></pre></bdo></b><th id='kd5sQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='kd5sQ'><tfoot id='kd5sQ'></tfoot><dl id='kd5sQ'><fieldset id='kd5sQ'></fieldset></dl></div>
                1. 本文介紹了確保 PHP 中的有效 UTF-8的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我使用 PHP 來處理來自各種來源的文本.我不認為它會是 UTF-8 以外的任何東西,ISO 8859-1 或 Windows-1252.如果不是其中之一,我只需要確保文本變成有效的 UTF-8 字符串,即使字符丟失.iconv 的//TRANSLIT 選項可以解決這個問題嗎?

                  I'm using PHP to handle text from a variety of sources. I don't anticipate it will be anything other than UTF-8, ISO 8859-1, or perhaps Windows-1252. If it's anything other than one of those, I just need to make sure the text gets turned into a valid UTF-8 string, even if characters are lost. Does the //TRANSLIT option of iconv solve this?

                  例如,此代碼能否確保將字符串安全地插入到 UTF-8 編碼的文檔(或數據庫)中?

                  For example, would this code ensure that a string is safe to insert into a UTF-8 encoded document (or database)?

                  function make_safe_for_utf8_use($string) {
                  
                      $encoding = mb_detect_encoding($string, "UTF-8,ISO-8859-1,WINDOWS-1252");
                  
                      if ($encoding != 'UTF-8') {
                          return iconv($encoding, 'UTF-8//TRANSLIT', $string);
                      }
                      else {
                          return $string;
                      }
                  }
                  

                  推薦答案

                  UTF-8 可以存儲任何 Unicode 字符.如果您的編碼完全不同,包括 ISO-8859-1 或 Windows-1252,則 UTF-8 可以存儲其中的每個字符.因此,當您將字符串從任何其他編碼轉換為 UTF-8 時,您不必擔心丟失任何字符.

                  UTF-8 can store any Unicode character. If your encoding is anything else at all, including ISO-8859-1 or Windows-1252, UTF-8 can store every character in it. So you don't have to worry about losing any characters when you convert a string from any other encoding to UTF-8.

                  此外,ISO-8859-1 和 Windows-1252 都是單字節編碼,其中任何字節都是有效的.在技??術上無法區分它們.我會選擇 Windows-1252 作為非 UTF-8 序列的默認匹配,因為唯一解碼不同的字節是范圍 0x80-0x9F.這些解碼為各種字符,如 Windows-1252 中的智能引號和歐元,而在 ISO-8859-1 中,它們是幾乎從未使用過的不可見控制字符.網絡瀏覽器有時可能會說他們使用的是 ISO-8859-1,但通常他們真的會使用 Windows-1252.

                  Further, both ISO-8859-1 and Windows-1252 are single-byte encodings where any byte is valid. It is not technically possible to distinguish between them. I would chose Windows-1252 as your default match for non-UTF-8 sequences, as the only bytes that decode differently are the range 0x80-0x9F. These decode to various characters like smart quotes and the Euro in Windows-1252, whereas in ISO-8859-1 they are invisible control characters which are almost never used. Web browsers may sometimes say they are using ISO-8859-1, but often they will really be using Windows-1252.

                  此代碼是否可以確保將字符串安全地插入到 UTF-8 編碼的文檔中

                  would this code ensure that a string is safe to insert into a UTF-8 encoded document

                  為此,您當然希望將可選的strict"參數設置為 TRUE.但我不確定這是否真的涵蓋了所有無效的 UTF-8 序列.該函數不要求明確檢查字節序列的 UTF-8 有效性.已知有 mb_detect_encoding 之前會錯誤地猜測 UTF-8 的情況,但我不知道在嚴格模式下是否仍然會發生這種情況.

                  You would certainly want to set the optional ‘strict’ parameter to TRUE for this purpose. But I'm not sure this actually covers all invalid UTF-8 sequences. The function does not claim to check a byte sequence for UTF-8 validity explicitly. There have been known cases where mb_detect_encoding would guess UTF-8 incorrectly before, though I don't know if that can still happen in strict mode.

                  如果您想確定,請使用 W3 推薦的正則表達式:

                  If you want to be sure, do it yourself using the W3-recommended regex:

                  if (preg_match('%^(?:
                        [x09x0Ax0Dx20-x7E]            # ASCII
                      | [xC2-xDF][x80-xBF]             # non-overlong 2-byte
                      | xE0[xA0-xBF][x80-xBF]         # excluding overlongs
                      | [xE1-xECxEExEF][x80-xBF]{2}  # straight 3-byte
                      | xED[x80-x9F][x80-xBF]         # excluding surrogates
                      | xF0[x90-xBF][x80-xBF]{2}      # planes 1-3
                      | [xF1-xF3][x80-xBF]{3}          # planes 4-15
                      | xF4[x80-x8F][x80-xBF]{2}      # plane 16
                  )*$%xs', $string))
                      return $string;
                  else
                      return iconv('CP1252', 'UTF-8', $string);
                  

                  這篇關于確保 PHP 中的有效 UTF-8的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 找不到驅動程序)

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

                    <tfoot id='AdBOi'></tfoot>

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

                            <tbody id='AdBOi'></tbody>
                          1. 主站蜘蛛池模板: 欧美日韩一 | 黄色香蕉视频在线观看 | 国产精品日韩高清伦字幕搜索 | 日韩精品在线观看一区二区 | 久久久国产一区二区三区四区小说 | 久久伊人操 | 欧美性生活网 | 久草欧美 | 男女视频在线免费观看 | 亚洲精品自在在线观看 | 免费看91| 成人三级在线播放 | 精产国产伦理一二三区 | 精品久久久久久久久久久久 | 91国内在线观看 | 欧美最猛性xxxxx亚洲精品 | 日韩一区二区三区在线 | www.久久久久久久久久久久 | 日韩精品在线播放 | 91精品久久久 | 欧洲视频一区二区 | 亚洲国产网站 | 免费观看黄网站 | 成人午夜精品一区二区三区 | 亚洲高清成人 | av香蕉 | 91xxx在线观看 | 国产一区二区三区视频免费观看 | 日韩视频区 | 欧美成人自拍 | 日韩精品一区二区三区在线播放 | 欧美日韩综合一区 | 亚洲精品欧美一区二区三区 | 久久亚洲一区二区 | 国产精品.xx视频.xxtv | 午夜精品一区 | 成人欧美一区二区三区 | 成人免费淫片aa视频免费 | 欧美精品一区二区免费视频 | 久久久精品网 | 亚洲天堂精品久久 |