框架在 StringField.php 文件中提供 LimitWordCount。它很棒,但并不完全完美。一些标签和标点符号需要更正。 我想要 :
<sup><sub><em>
我做了自己的LimitWordCount:
public function MyLimitWordCount($int) {
$text = strip_tags($this->owner->value, '<sup><sub><em>');
if (str_word_count($text, 0) > $int) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$int]) . '…';
}
$text = str_replace('.', '. ', $text );
$text = str_replace('!', '! ', $text );
$text = str_replace('…', '… ', $text );
$text = str_replace('?', '? ', $text );
return $text;
}
这并不完全有效。一些标点符号未更正,并且在 HTMLEditor 字段中制作的视频短代码
[embed width="480...]
与我的功能保持一致。我不知道他做错了什么。
您将继续在文本中获取短代码,因为您需要先解析它们。
使用
(string)$this->owner->dbObject('value')
而不是 $this->owner->value
最容易解决此问题。
然后您可以操作短代码已展开的值。
我无法评论为什么在这种情况下你的标点符号没有被“纠正”,因为你没有提供关于哪些标点符号以及在什么情况下它不起作用的太多信息。