pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

  • <legend id='r11w6'><style id='r11w6'><dir id='r11w6'><q id='r11w6'></q></dir></style></legend>

      <tfoot id='r11w6'></tfoot>
      1. <i id='r11w6'><tr id='r11w6'><dt id='r11w6'><q id='r11w6'><span id='r11w6'><b id='r11w6'><form id='r11w6'><ins id='r11w6'></ins><ul id='r11w6'></ul><sub id='r11w6'></sub></form><legend id='r11w6'></legend><bdo id='r11w6'><pre id='r11w6'><center id='r11w6'></center></pre></bdo></b><th id='r11w6'></th></span></q></dt></tr></i><div class="d7tlp7p" id='r11w6'><tfoot id='r11w6'></tfoot><dl id='r11w6'><fieldset id='r11w6'></fieldset></dl></div>
          <bdo id='r11w6'></bdo><ul id='r11w6'></ul>
      2. 使用 PHP 轉(zhuǎn)換所有類型的智能引號

        Convert all types of smart quotes with PHP(使用 PHP 轉(zhuǎn)換所有類型的智能引號)

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

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

              <legend id='izrke'><style id='izrke'><dir id='izrke'><q id='izrke'></q></dir></style></legend>

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

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

                1. 本文介紹了使用 PHP 轉(zhuǎn)換所有類型的智能引號的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在嘗試在處理文本時將所有類型的智能引號轉(zhuǎn)換為常規(guī)引號.但是,我編譯的以下函數(shù)似乎仍然缺乏支持和適當(dāng)?shù)脑O(shè)計.

                  I am trying to convert all types of smart quotes to regular quotes when working with text. However, the following function I've compiled still seems to be lacking support and proper design.

                  有誰知道如何正確轉(zhuǎn)換所有引號字符?

                  Does anyone know how to properly get all quote characters converted?

                  function convert_smart_quotes($string)
                  {
                      $quotes = array(
                          "xC2xAB"   => '"', // ? (U+00AB) in UTF-8
                          "xC2xBB"   => '"', // ? (U+00BB) in UTF-8
                          "xE2x80x98" => "'", // ‘ (U+2018) in UTF-8
                          "xE2x80x99" => "'", // ’ (U+2019) in UTF-8
                          "xE2x80x9A" => "'", // ? (U+201A) in UTF-8
                          "xE2x80x9B" => "'", // ? (U+201B) in UTF-8
                          "xE2x80x9C" => '"', // " (U+201C) in UTF-8
                          "xE2x80x9D" => '"', // " (U+201D) in UTF-8
                          "xE2x80x9E" => '"', // ? (U+201E) in UTF-8
                          "xE2x80x9F" => '"', // ? (U+201F) in UTF-8
                          "xE2x80xB9" => "'", // ? (U+2039) in UTF-8
                          "xE2x80xBA" => "'", // ? (U+203A) in UTF-8
                      );
                      $string = strtr($string, $quotes);
                  
                      // Version 2
                      $search = array(
                          chr(145),
                          chr(146),
                          chr(147),
                          chr(148),
                          chr(151)
                      );
                      $replace = array("'","'",'"','"',' - ');
                      $string = str_replace($search, $replace, $string);
                  
                      // Version 3
                      $string = str_replace(
                          array('&#8216;','&#8217;','&#8220;','&#8221;'),
                          array("'", "'", '"', '"'),
                          $string
                      );
                  
                      // Version 4
                      $search = array(
                          '&lsquo;', 
                          '&rsquo;', 
                          '&ldquo;', 
                          '&rdquo;', 
                          '&mdash;',
                          '&ndash;',
                      );
                      $replace = array("'","'",'"','"',' - ', '-');
                      $string = str_replace($search, $replace, $string);
                  
                      return $string;
                  }
                  

                  注意:這個問題是一個完整的查詢,包括此處詢問Microsoft"引號 這是一個重復(fù)",就像詢問所有輪胎尺寸是詢問汽車輪胎尺寸的重復(fù)"一樣.

                  Note: This question is a complete query about the full of gamut of quotes including the "Microsoft" quotes asked here This is a "duplicate" in the same way that asking about all tire sizes is a "duplicate" of asking for a car tire size.

                  推薦答案

                  你需要這樣的東西(假設(shè) UTF-8 輸入,忽略 CJK(中文、日語、韓語)):

                  You need something like this (assuming UTF-8 input, and ignoring CJK (Chinese, Japanese, Korean)):

                  $chr_map = array(
                     // Windows codepage 1252
                     "xC2x82" => "'", // U+0082?U+201A single low-9 quotation mark
                     "xC2x84" => '"', // U+0084?U+201E double low-9 quotation mark
                     "xC2x8B" => "'", // U+008B?U+2039 single left-pointing angle quotation mark
                     "xC2x91" => "'", // U+0091?U+2018 left single quotation mark
                     "xC2x92" => "'", // U+0092?U+2019 right single quotation mark
                     "xC2x93" => '"', // U+0093?U+201C left double quotation mark
                     "xC2x94" => '"', // U+0094?U+201D right double quotation mark
                     "xC2x9B" => "'", // U+009B?U+203A single right-pointing angle quotation mark
                  
                     // Regular Unicode     // U+0022 quotation mark (")
                                            // U+0027 apostrophe     (')
                     "xC2xAB"     => '"', // U+00AB left-pointing double angle quotation mark
                     "xC2xBB"     => '"', // U+00BB right-pointing double angle quotation mark
                     "xE2x80x98" => "'", // U+2018 left single quotation mark
                     "xE2x80x99" => "'", // U+2019 right single quotation mark
                     "xE2x80x9A" => "'", // U+201A single low-9 quotation mark
                     "xE2x80x9B" => "'", // U+201B single high-reversed-9 quotation mark
                     "xE2x80x9C" => '"', // U+201C left double quotation mark
                     "xE2x80x9D" => '"', // U+201D right double quotation mark
                     "xE2x80x9E" => '"', // U+201E double low-9 quotation mark
                     "xE2x80x9F" => '"', // U+201F double high-reversed-9 quotation mark
                     "xE2x80xB9" => "'", // U+2039 single left-pointing angle quotation mark
                     "xE2x80xBA" => "'", // U+203A single right-pointing angle quotation mark
                  );
                  $chr = array_keys  ($chr_map); // but: for efficiency you should
                  $rpl = array_values($chr_map); // pre-calculate these two arrays
                  $str = str_replace($chr, $rpl, html_entity_decode($str, ENT_QUOTES, "UTF-8"));
                  

                  這里是背景:

                  每個 Unicode 字符都只屬于一個 "General Category",其中可以包含引號的字符字符如下:

                  Every Unicode character belongs to exactly one "General Category", of which the ones that can contain quote characters are the following:

                  • Ps 標(biāo)點符號,打開"
                  • Pe 標(biāo)點符號,關(guān)閉"
                  • Pi "標(biāo)點符號、初始引號(可能表現(xiàn)得像 Ps 或Pe 取決于使用情況)"
                  • Pf "標(biāo)點符號,最后引用(可能表現(xiàn)得像 Ps 或Pe 取決于使用情況)"
                  • Po 標(biāo)點符號,其他"

                  (這些頁面可以方便地檢查您是否沒有遺漏任何內(nèi)容 - 還有一個 索引類別)

                  (these pages are handy for checking that you didn't miss anything - there is also an index of categories)

                  有時在支持 Unicode 的正則表達(dá)式中匹配這些類別很有用.

                  It is sometimes useful to match these categories in a Unicode-enabled regex.

                  此外,Unicode 字符具有屬性",其中您感興趣的是Quotation_Mark.不幸的是,這些不能在正則表達(dá)式中訪問.

                  Furthermore, Unicode characters have "properties", of which the one you are interested in is Quotation_Mark. Unfortunately, these are not accessible in a regex.

                  在維基百科中,您可以找到具有 Quotation_Mark 屬性的字符組.最后一個參考是 unicode.org 上的 PropList.txt,但這是一個 ASCII 文本文件.

                  In Wikipedia you can find the group of characters with the Quotation_Mark property. The final reference is PropList.txt on unicode.org, but this is an ASCII textfile.

                  如果您也需要翻譯 CJK 字符,您只需獲取它們的代碼點,決定它們的翻譯,并找到它們的 UTF-8 編碼,例如,通過在 fileformat.info 中查找(例如,對于 U+301E:http://www.fileformat.info/info/unicode/char/301e/index.htmlhtm).

                  In case you need to translate CJK characters too, you only have to get their code points, decide their translation, and find their UTF-8 encoding, e.g., by looking it up in fileformat.info (e.g., for U+301E: http://www.fileformat.info/info/unicode/char/301e/index.htm).

                  關(guān)于 Windows 代碼頁 1252:Unicode 定義了前 256 個代碼點來表示與 ISO-8859-1,但 ISO-8859-1 經(jīng)常與 Windows 代碼頁 1252,以便所有瀏覽器呈現(xiàn)范圍 0x80-0x9F,這在 ISO-8859-1 中為空"(更準(zhǔn)確地說:它包含控制字符),就好像它是 Windows 代碼頁 1252.維基百科頁面中的表格列出了 Unicode 等效項.

                  Regarding Windows codepage 1252: Unicode defines the first 256 code points to represent exactly the same characters as ISO-8859-1, but ISO-8859-1 is often confused with Windows codepage 1252, so that all browsers render the range 0x80-0x9F, which is "empty" in ISO-8859-1 (more exactly: it contains control characters), as if it were Windows codepage 1252. The table in the Wikipedia page lists the Unicode equivalents.

                  注意:strtr() 通常比 str_replace().使用您的輸入和 PHP 版本計時.如果速度夠快,可以直接用我的$chr_map之類的地圖.

                  如果您不確定您的輸入是否是 UTF-8 編碼,并且愿意假設(shè)如果不是,那么它是 ISO-8859-1 或 Windows 代碼頁 1252,那么您可以先執(zhí)行此操作:

                  If you are not sure that your input is UTF-8 encoded, AND are willing to assume that if it's not, then it's ISO-8859-1 or Windows codepage 1252, then you can do this before anything else:

                  if ( !preg_match('/^\X*$/u', $str)) {
                     $str = utf8_encode($str);
                  }
                  

                  警告:這個正則表達(dá)式在極少數(shù)情況下可能無法檢測到非 UTF-8 編碼.例如:"Gru?..."/*CP-1252*/=="GruxDFx85" 看起來像這個正則表達(dá)式的 UTF-8(U+07C5 是 N'ko 數(shù)字 5).這個正則表達(dá)式可以稍微增強(qiáng),但不幸的是,它可以表明對于編碼檢測問題不存在完全萬無一失的解決方案.

                  Warning: this regex can in very rare cases fail to detect a non-UTF-8 encoding, though. E.g.: "Gru?…"/*CP-1252*/=="GruxDFx85" looks like UTF-8 to this regex (U+07C5 is the N'ko digit 5). This regex can be slightly enhanced, but unfortunately it can be shown that there exists NO completely foolproof solution to the problem of encoding detection.

                  如果您想將源自 Windows 代碼頁 1252 的范圍 0x80-0x9F 標(biāo)準(zhǔn)化為常規(guī) Unicode 代碼點,您可以這樣做(并刪除上面$chr_map 的第一部分):

                  If you want to normalize the range 0x80-0x9F that stems from Windows codepage 1252 to regular Unicode codepoints, you can do this (and remove the first part of the $chr_map above):

                  $normalization_map = array(
                     "xC2x80" => "xE2x82xAC", // U+20AC Euro sign
                     "xC2x82" => "xE2x80x9A", // U+201A single low-9 quotation mark
                     "xC2x83" => "xC6x92",     // U+0192 latin small letter f with hook
                     "xC2x84" => "xE2x80x9E", // U+201E double low-9 quotation mark
                     "xC2x85" => "xE2x80xA6", // U+2026 horizontal ellipsis
                     "xC2x86" => "xE2x80xA0", // U+2020 dagger
                     "xC2x87" => "xE2x80xA1", // U+2021 double dagger
                     "xC2x88" => "xCBx86",     // U+02C6 modifier letter circumflex accent
                     "xC2x89" => "xE2x80xB0", // U+2030 per mille sign
                     "xC2x8A" => "xC5xA0",     // U+0160 latin capital letter s with caron
                     "xC2x8B" => "xE2x80xB9", // U+2039 single left-pointing angle quotation mark
                     "xC2x8C" => "xC5x92",     // U+0152 latin capital ligature oe
                     "xC2x8E" => "xC5xBD",     // U+017D latin capital letter z with caron
                     "xC2x91" => "xE2x80x98", // U+2018 left single quotation mark
                     "xC2x92" => "xE2x80x99", // U+2019 right single quotation mark
                     "xC2x93" => "xE2x80x9C", // U+201C left double quotation mark
                     "xC2x94" => "xE2x80x9D", // U+201D right double quotation mark
                     "xC2x95" => "xE2x80xA2", // U+2022 bullet
                     "xC2x96" => "xE2x80x93", // U+2013 en dash
                     "xC2x97" => "xE2x80x94", // U+2014 em dash
                     "xC2x98" => "xCBx9C",     // U+02DC small tilde
                     "xC2x99" => "xE2x84xA2", // U+2122 trade mark sign
                     "xC2x9A" => "xC5xA1",     // U+0161 latin small letter s with caron
                     "xC2x9B" => "xE2x80xBA", // U+203A single right-pointing angle quotation mark
                     "xC2x9C" => "xC5x93",     // U+0153 latin small ligature oe
                     "xC2x9E" => "xC5xBE",     // U+017E latin small letter z with caron
                     "xC2x9F" => "xC5xB8",     // U+0178 latin capital letter y with diaeresis
                  );
                  $chr = array_keys  ($normalization_map); // but: for efficiency you should
                  $rpl = array_values($normalization_map); // pre-calculate these two arrays
                  $str = str_replace($chr, $rpl, $str);
                  

                  這篇關(guān)于使用 PHP 轉(zhuǎn)換所有類型的智能引號的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  enable SOAP on PHP(在 PHP 上啟用 SOAP)
                  Get received XML from PHP SOAP Server(從 PHP SOAP 服務(wù)器獲取接收到的 XML)
                  not a valid AllXsd value(不是有效的 AllXsd 值)
                  PHP SoapClient: SoapFault exception Could not connect to host(PHP SoapClient:SoapFault 異常無法連接到主機(jī))
                  Implementation of P_SHA1 algorithm in PHP(PHP中P_SHA1算法的實現(xiàn))
                  Sending a byte array from PHP to WCF(將字節(jié)數(shù)組從 PHP 發(fā)送到 WCF)
                  • <i id='ByDMa'><tr id='ByDMa'><dt id='ByDMa'><q id='ByDMa'><span id='ByDMa'><b id='ByDMa'><form id='ByDMa'><ins id='ByDMa'></ins><ul id='ByDMa'></ul><sub id='ByDMa'></sub></form><legend id='ByDMa'></legend><bdo id='ByDMa'><pre id='ByDMa'><center id='ByDMa'></center></pre></bdo></b><th id='ByDMa'></th></span></q></dt></tr></i><div class="n5zdjjn" id='ByDMa'><tfoot id='ByDMa'></tfoot><dl id='ByDMa'><fieldset id='ByDMa'></fieldset></dl></div>
                      <bdo id='ByDMa'></bdo><ul id='ByDMa'></ul>
                        <tbody id='ByDMa'></tbody>
                      <tfoot id='ByDMa'></tfoot>

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

                            <legend id='ByDMa'><style id='ByDMa'><dir id='ByDMa'><q id='ByDMa'></q></dir></style></legend>
                          1. 主站蜘蛛池模板: 闸阀_截止阀_止回阀「生产厂家」-上海卡比阀门有限公司 | SDG吸附剂,SDG酸气吸附剂,干式酸性气体吸收剂生产厂家,超过20年生产使用经验。 - 富莱尔环保设备公司(原名天津市武清县环保设备厂) | 洁净棚-洁净工作棚-无菌室-净化工程公司_北京卫护科技有限公司 | 防爆电机-高压防爆电机-ybx4电动机厂家-河南省南洋防爆电机有限公司 | 釜溪印象网络 - Powered by Discuz! | 定制液氮罐_小型气相液氮罐_自增压液氮罐_班德液氮罐厂家 | 合景一建-无尘车间设计施工_食品医药洁净车间工程装修总承包公司 | 立式壁挂广告机厂家-红外电容触摸一体机价格-华邦瀛 | 金环宇|金环宇电线|金环宇电缆|金环宇电线电缆|深圳市金环宇电线电缆有限公司|金环宇电缆集团 | 液氨泵,液化气泵-淄博「亚泰」燃气设备制造有限公司 | 【同风运车官网】一站式汽车托运服务平台,验车满意再付款 | 幂简集成 - 品种超全的API接口平台, 一站搜索、试用、集成国内外API接口 | 24位ADC|8位MCU-芯易德科技有限公司| 农产品溯源系统_农产品质量安全追溯系统_溯源系统 | 定制防伪标签_防伪标签印刷_防伪标签厂家-510品保防伪网 | 全国国际学校排名_国际学校招生入学及学费-学校大全网 | 微量水分测定仪_厂家_卡尔费休微量水分测定仪-淄博库仑 | 钢丝绳探伤仪-钢丝绳检测仪-钢丝绳探伤设备-洛阳泰斯特探伤技术有限公司 | 2025世界机器人大会_IC China_半导体展_集成电路博览会_智能制造展览网 | 成都亚克力制品,PVC板,双色板雕刻加工,亚克力门牌,亚克力标牌,水晶字雕刻制作-零贰捌广告 | 多功能真空滤油机_润滑油全自动滤油机_高效真空滤油机价格-重庆润华通驰 | 储能预警-储能消防系统-电池舱自动灭火装置-四川千页科技股份有限公司官网 | 涡街流量计_LUGB智能管道式高温防爆蒸汽温压补偿计量表-江苏凯铭仪表有限公司 | 北京宣传片拍摄_产品宣传片拍摄_宣传片制作公司-现像传媒 | 不干胶标签,不干胶标签纸_厂家-山东同力胶粘制品 | 活动策划,舞台搭建,活动策划公司-首选美湖上海活动策划公司 | 高压互感器,电流互感器,电压互感器-上海鄂互电气科技有限公司 | 应急灯_消防应急灯_应急照明灯_应急灯厂家-大成智慧官网 | 工业淬火油烟净化器,北京油烟净化器厂家,热处理油烟净化器-北京众鑫百科 | 临朐空调移机_空调维修「空调回收」临朐二手空调 | CE认证_FCC认证_CCC认证_MFI认证_UN38.3认证-微测检测 CNAS实验室 | 液压扳手-高品质液压扳手供应商 - 液压扳手, 液压扳手供应商, 德国进口液压拉马 | 粉末冶金注射成型厂家|MIM厂家|粉末冶金齿轮|MIM零件-深圳市新泰兴精密科技 | SDG吸附剂,SDG酸气吸附剂,干式酸性气体吸收剂生产厂家,超过20年生产使用经验。 - 富莱尔环保设备公司(原名天津市武清县环保设备厂) | 江苏密集柜_电动_手动_移动_盛隆柜业江苏档案密集柜厂家 | 棕刚玉-白刚玉厂家价格_巩义市东翔净水材料厂 | LED显示屏_LED屏方案设计精准报价专业安装丨四川诺显科技 | HYDAC过滤器,HYDAC滤芯,现货ATOS油泵,ATOS比例阀-东莞市广联自动化科技有限公司 | 环保袋,无纺布袋,无纺布打孔袋,保温袋,环保袋定制,环保袋厂家,环雅包装-十七年环保袋定制厂家 | 托利多电子平台秤-高精度接线盒-托利多高精度电子秤|百科 | 板材品牌-中国胶合板行业十大品牌-环保板材-上海声达板材 |