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

<small id='7YYKT'></small><noframes id='7YYKT'>

    • <bdo id='7YYKT'></bdo><ul id='7YYKT'></ul>
    <i id='7YYKT'><tr id='7YYKT'><dt id='7YYKT'><q id='7YYKT'><span id='7YYKT'><b id='7YYKT'><form id='7YYKT'><ins id='7YYKT'></ins><ul id='7YYKT'></ul><sub id='7YYKT'></sub></form><legend id='7YYKT'></legend><bdo id='7YYKT'><pre id='7YYKT'><center id='7YYKT'></center></pre></bdo></b><th id='7YYKT'></th></span></q></dt></tr></i><div class="622u0q2" id='7YYKT'><tfoot id='7YYKT'></tfoot><dl id='7YYKT'><fieldset id='7YYKT'></fieldset></dl></div>
    1. <legend id='7YYKT'><style id='7YYKT'><dir id='7YYKT'><q id='7YYKT'></q></dir></style></legend>
      <tfoot id='7YYKT'></tfoot>

        在 UTF-8 編碼的字符串上使用 str_split

        Using str_split on a UTF-8 encoded string(在 UTF-8 編碼的字符串上使用 str_split)

          <small id='24vnV'></small><noframes id='24vnV'>

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

            • <legend id='24vnV'><style id='24vnV'><dir id='24vnV'><q id='24vnV'></q></dir></style></legend>
                <tbody id='24vnV'></tbody>
              <tfoot id='24vnV'></tfoot>
                  <bdo id='24vnV'></bdo><ul id='24vnV'></ul>
                  本文介紹了在 UTF-8 編碼的字符串上使用 str_split的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我目前正在處理一個項目,我想我應(yīng)該繼續(xù)學(xué)習(xí)如何使用 PDO,而不是使用常規(guī)的 MySQL 查詢.

                  I'm currently working on a project, and instead of using regular MySQL queries I thought I'd go ahead and learn how to use PDO.

                  我有一個表叫參賽者,數(shù)據(jù)庫、表和所有的列都是utf-8.我在參賽者表中有十個條目,它們的名稱"列包含 ??? 等字符.

                  I have a table called contestants, both the database, the table, and all of the columns are in utf-8. I have ten entries in the contestant table, and their column "name" contains characters such as ???.

                  現(xiàn)在,當(dāng)我從數(shù)據(jù)庫中獲取一個條目并使用 var_dump 名稱時,我得到了一個很好的結(jié)果,一個包含所有特殊字符的字符串.但我需要做的是將字符串按字符拆分,將它們放入一個數(shù)組中,然后再進(jìn)行洗牌.

                  Now, when I fetch an entry from the database, and var_dump the name, I get a good result, a string with all the special characters intact. But what I need to do is to split the string by characters, to get them in an array that I then shuffle.

                  例如,我有這個字符串:測試 ??? T??n

                  For instance, I have this string: Test ??? T??n

                  當(dāng)我運行 str_split 時,我將每個字符放入數(shù)組中它自己的鍵中.唯一的問題是所有特殊字符都顯示為: ,意味著數(shù)組將如下所示:

                  And when I run str_split I get each character in it's own key in an array. The only issue is that all the special characters display as this: ?, meaning the array will be like this:

                  Array
                  (
                      [0] => T
                      [1] => e
                      [2] => s
                      [3] => t
                      [4] =>  
                      [5] => ?
                      [6] => ?
                      [7] => ?
                      [8] => ?
                      [9] => ?
                      [10] => ?
                      [11] =>  
                      [12] => T
                      [13] => ?
                      [14] => ?
                      [15] => ?
                      [16] => ?
                      [17] => n
                  )
                  

                  如您所見,它不僅會弄亂字符,還會在 str_split 過程中復(fù)制它們.我嘗試了幾種拆分字符串的方法,但它們都有相同的問題.當(dāng)我在拆分之前輸出字符串時,它顯示特殊字符就好了.

                  As you can see, it not only messes up the characters, but it also duplicates them in str_split process. I've tried several ways to split the string, but they all have the same issue. When I output the string before the split, it shows the special characters just fine.

                  這是我的 dbConn.php 代碼:

                  This is my dbConn.php code:

                  //需要配置文件:require_once('config.inc.php');

                  // Require config file: require_once('config.inc.php');

                  // Start PDO connection:
                  $dbHandle = new PDO("mysql:host=$dbHost;dbname=$dbName;charset=utf-8", $dbUser, $dbPass);
                  $dbHandle -> exec("SET CHARACTER SET utf8");
                  
                  // Set error reporting:
                  $dbHandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
                  

                  這是我用來從數(shù)據(jù)庫中獲取并循環(huán)的代碼:

                  And this is the code that I use to fetch from the database and loop:

                  // Require files:
                  require_once('dbConn.php');
                  
                  // Get random artist:
                  $artist = $dbHandle->query("SELECT * FROM ".ARTIST_TABLE." WHERE id = 11 ORDER BY RAND() LIMIT 1");
                  $artist->setFetchMode(PDO::FETCH_OBJ);
                  $artist = $artist->fetch();
                  var_dump($artist->name);
                  
                  // Split name:
                  $artistChars = str_split($artist->name);
                  

                  我使用 utf-8 連接,我的 php 文件是 utf-8 沒有 BOM 并且此頁面上沒有其他特殊字符共享此問題.可能有什么問題,或者我做錯了什么?

                  I'm connecting with utf-8, my php file is utf-8 without BOM and no other special characters on this page share this issue. What could be wrong, or what am I doing wrong?

                  推薦答案

                  str_split 不適用于 multi-byte 字符,它只會返回第一個字節(jié) - 從而使您的字符無效.你可以使用 mb_split.

                  這篇關(guān)于在 UTF-8 編碼的字符串上使用 str_split的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

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

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

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

                            主站蜘蛛池模板: 德州万泰装饰 - 万泰装饰装修设计软装家居馆 | 校车_校车价格_19座幼儿园校车_幼儿园校车_大鼻子校车 | 磁粉制动器|张力控制器|气胀轴|伺服纠偏控制器整套厂家--台灵机电官网 | 首页_欧瑞传动官方网站--主营变频器、伺服系统、新能源、软起动器、PLC、HMI | 全自动烧卖机厂家_饺子机_烧麦机价格_小笼汤包机_宁波江北阜欣食品机械有限公司 | 英语词典_成语词典_日语词典_法语词典_在线词典网 | 石油/泥浆/不锈钢防腐/砂泵/抽砂泵/砂砾泵/吸砂泵/压滤机泵 - 专业石油环保专用泵厂家 | 企业彩铃制作_移动、联通、电信集团彩铃上传开通_彩铃定制_商务彩铃管理平台-集团彩铃网 | 首页 - 军军小站|张军博客 | ORP控制器_ORP电极价格-上优泰百科 | 耐酸泵,耐腐蚀真空泵,耐酸真空泵-淄博华舜耐腐蚀真空泵有限公司 精密模具-双色注塑模具加工-深圳铭洋宇通 | 优秀的临床医学知识库,临床知识库,医疗知识库,满足电子病历四级要求,免费试用 | 一体化净水器_一体化净水设备_一体化水处理设备-江苏旭浩鑫环保科技有限公司 | 华东师范大学在职研究生招生网_在职研究生招生联展网 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 地脚螺栓_材质_标准-永年县德联地脚螺栓厂家 | 钢托盘,钢制托盘,立库钢托盘,金属托盘制造商_南京飞天金属制品实业有限公司 | 数控专用机床,专用机床,自动线,组合机床,动力头,自动化加工生产线,江苏海鑫机床有限公司 | 3d可视化建模_三维展示_产品3d互动数字营销_三维动画制作_3D虚拟商城 【商迪3D】三维展示服务商 广东健伦体育发展有限公司-体育工程配套及销售运动器材的体育用品服务商 | 赛默飞Thermo veritiproPCR仪|ProFlex3 x 32PCR系统|Countess3细胞计数仪|371|3111二氧化碳培养箱|Mirco17R|Mirco21R离心机|仟诺生物 | 名律网-法律问题咨询-找律师-法律知识| 免费网站网址收录网_海企优网站推荐平台 | 分子精馏/精馏设备生产厂家-分子蒸馏工艺实验-新诺舜尧(天津)化工设备有限公司 | 煤矿支护网片_矿用勾花菱形网_缝管式_管缝式锚杆-邯郸市永年区志涛工矿配件有限公司 | 洛阳装修公司-洛阳整装一站式品牌-福尚云宅装饰 | 外观设计_设备外观设计_外观设计公司_产品外观设计_机械设备外观设计_东莞工业设计公司-意品深蓝 | SF6环境监测系统-接地环流在线监测装置-瑟恩实业 | SRRC认证_电磁兼容_EMC测试整改_FCC认证_SDOC认证-深圳市环测威检测技术有限公司 | 行星齿轮减速机,减速机厂家,山东减速机-淄博兴江机械制造 | 全自动包装秤_全自动上袋机_全自动套袋机_高位码垛机_全自动包装码垛系统生产线-三维汉界机器(山东)股份有限公司 | 铜镍-康铜-锰铜-电阻合金-NC003 - 杭州兴宇合金有限公司 | 金属切削液-脱水防锈油-电火花机油-抗磨液压油-深圳市雨辰宏业科技发展有限公司 | 工业车间焊接-整体|集中除尘设备-激光|等离子切割机配套除尘-粉尘烟尘净化治理厂家-山东美蓝环保科技有限公司 | TYPE-C厂家|TYPE-C接口|TYPE-C防水母座|TYPE-C贴片-深圳步步精 | 螺杆泵_中成泵业 | 深圳宣传片制作-企业宣传视频制作-产品视频拍摄-产品动画制作-短视频拍摄制作公司 | YAGEO国巨电容|贴片电阻|电容价格|三星代理商-深圳市巨优电子有限公司 | 全国国际学校排名_国际学校招生入学及学费-学校大全网 | 泰安塞纳春天装饰公司【网站】| 重庆钣金加工厂家首页-专业定做监控电视墙_操作台 | 科昊仪器超纯水机系统-可成气相液氮罐-美菱超低温冰箱-西安昊兴生物科技有限公司 |