Help us understand the problem. What is going on with this article?

TeamPassのitem一覧でdescriptionのトリミングがマルチバイトを理解しない問題の対策

More than 3 years have passed since last update.

TeamPass というパスワード管理ツールがあるのですが、項目一覧で説明(description)のところを30文字に切り詰める処理がマルチバイト理解しないので、変なところで切り詰められてしまいます。

とりあえず substr() を mb_substr() に変更することで回避しました。
できれば文字幅を考慮すべきですが、実害がないのでマルチバイトでも30文字のままにしています。

sources/items.queries.php- sources/items.queries.php
--- sources/items.queries.php-  2016-08-16 05:03:17.000000000 +0900
+++ sources/items.queries.php   2016-11-29 17:53:16.128242854 +0900
@@ -314,7 +314,7 @@
                 '&nbsp;<a id="fileclass'.$newID.'" class="file" onclick="AfficherDetailsItem(\''.$newID.'\', \'0\', \'\', \'\', \'\', \'\', \'\')" ondblclick="AfficherDetailsItem(\''.$newID.'\', \'0\', \'\', \'\', \'\', true, \'\')">' .
                 stripslashes($dataReceived['label']);
                 if (!empty($dataReceived['description']) && isset($_SESSION['settings']['show_description']) && $_SESSION['settings']['show_description'] == 1) {
-                    $html .= '&nbsp;<font size=2px>['.strip_tags(stripslashes(substr(cleanString($dataReceived['description']), 0, 30))).']</font>';
+                    $html .= '&nbsp;<font size=2px>['.strip_tags(stripslashes(mb_substr(cleanString($dataReceived['description']), 0, 30))).']</font>';
                 }
                 $html .= '</a><span style="float:right;margin:2px 10px 0px 0px;">';
                 // mini icon for collab
@@ -1955,9 +1955,9 @@
                         if (!empty($record['description']) && isset($_SESSION['settings']['show_description']) && $_SESSION['settings']['show_description'] == 1) {
                             $tempo = explode("<br />", $record['description']);
                             if (count($tempo) == 1) {
-                                $html .= '&nbsp;<font size="2px">['.strip_tags(stripslashes(substr(cleanString($record['description']), 0, 30))).']</font>';
+                                $html .= '&nbsp;<font size="2px">['.strip_tags(stripslashes(mb_substr(cleanString($record['description']), 0, 30))).']</font>';
                             } else {
-                                $html .= '&nbsp;<font size="2px">['.strip_tags(stripslashes(substr(cleanString($tempo[0]), 0, 30))).']</font>';
+                                $html .= '&nbsp;<font size="2px">['.strip_tags(stripslashes(mb_substr(cleanString($tempo[0]), 0, 30))).']</font>';
                             }
                         }
                         $html .= '</a>';
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away