cakephpのtruncateについて
同じように文字数指定をして読み込んでいるはずなのに出力をカウントすると違った
htmlタグも読み込むかどうかの違いだったらしい。
デフォルトは読み込むになっているので純粋に文字数をカウントしたい場合は
lib/cake/utility/string.php
public static function truncate($text, $length = 100, $options = array()) {
$default = array(
'ellipsis' => '...', 'exact' => true, 'html' => true
);
'html' => trueだとhtmlタグもカウントする状態ですのでこれを
public static function truncate($text, $length = 100, $options = array()) {
$default = array(
'ellipsis' => '...', 'exact' => true, 'html' => false
);
に書き換えると文字だけカウントするようになります。