[請益] str_pad中英文混合時對不齊

看板PHP作者 (Sylvanas)時間15年前 (2010/06/02 14:57), 編輯推噓0(007)
留言7則, 3人參與, 最新討論串1/2 (看更多)
最近遇到了一個問題,不知道有人有解決方案嗎? 我在用str_pad的時候裡面有中英文混合就沒辦法對的齊 原始碼如下 <?php require_once "HTML/Template/IT.php"; $p_arr = array ("p_id" => "產品ID", "p_board" => "產品品牌(外部Table)", "p_model" => "產品型號", "p_category" => "產品分類(外部Table)", "p_warranty" => "產品保固", "p_memo" => "產品備註", ); $template = new HTML_Template_IT("./tpl"); $template->loadTemplatefile ("productFilePlaning.html", true, true); $template->setCurrentBlock("CUSTOMER"); foreach ($p_arr as $key => $value) { $value_padding = $key.str_pad ($value, 90, ".", STR_PAD_LEFT); $template->setVariable ("$key", $value_padding); } $template->parseCurrentBlock (); $template->show (); ?> 麻煩各位了,謝謝。 補一下輸出的html原始碼 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <style type="text/css"> ul {font-family:Monaco} </style> <title></title> </head> <body> <div id="header"> <h1>商品檔規劃書(SQL)</h1> </div> <div id="main"> <ul> <!-- BEGIN product --> <li>p_id................................產品ID</li> <li>p_board...............產品品牌(外部Table)</li> <li>p_model............................產品型號</li> <li>p_category...............產品分類(外部Table)</li> <li>p_warranty............................產品保固</li> <li>p_memo............................產品備註</li> <!-- BEGIN product --> </ul> </div> </body> </html> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.191.220 ※ 編輯: darklady 來自: 220.134.191.220 (06/02 14:59)

06/02 14:59, , 1F
我比較想知道你怎麼快速上色的...
06/02 14:59, 1F

06/02 14:59, , 2F
樓上,這是vim的顏色
06/02 14:59, 2F

06/02 15:00, , 3F
原po說的對不齊是什麼意思? 是因為不等寬字型的關係嗎?
06/02 15:00, 3F

06/02 15:01, , 4F
恩 不等寬的字型應該是比較大的可能性
06/02 15:01, 4F

06/02 15:01, , 5F
我有試過各種等寬字型了。
06/02 15:01, 5F

06/02 15:10, , 6F
我剛試了一下,就算全中文,也是補起來有問題
06/02 15:10, 6F
※ 編輯: darklady 來自: 220.134.191.220 (06/02 15:15) ※ 編輯: darklady 來自: 220.134.191.220 (06/02 15:15) ※ 編輯: darklady 來自: 220.134.191.220 (06/02 15:19)

06/02 15:29, , 7F
utf-8的中文字佔三個byte
06/02 15:29, 7F
文章代碼(AID): #1C1W3hdp (PHP)
文章代碼(AID): #1C1W3hdp (PHP)