Wordpress-精确文本修剪功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wordpress-精确文本修剪功能相关的知识,希望对你有一定的参考价值。

Add to your functions.php in the active template.

Remove commented text. Fat/Thin char detection still not implemented. I'll update it as soon as I get some time. If you come with it please let me know :)
  1. function pcsite_trim ($text, $maxwords, $allowtags = "") {
  2. // <?php echo pcsite_trim(get_the_content(), 15, "");
  3. // Strip tags
  4. $text = strip_tags($text, $allowtags);
  5.  
  6. //workingonthis-$thinchars = ereg_replace("[^fijlt]", "", $text);
  7. //workingonthis-$fatchars = ereg_replace("[^mw]", "", $text);
  8. //workingonthis-$modifier = 5.1 + ( (strlen($thinchars) / strlen($text)) - (strlen($fatchars) / strlen($text)) );
  9. $modifier = 5.1; // average letters per word (in normal english it's 4.5, but in blogging and so it increases)
  10.  
  11. $text = substr($text, 0, $maxwords * $modifier);
  12.  
  13. $words = explode(" ", $text);
  14. $words = array_slice($words, 0, count($words) - 1 );
  15.  
  16. // Array to text
  17. $text = implode(" ", $words);
  18. $text = "<p>".$text."...</p>";
  19.  
  20. return $text;
  21. }

以上是关于Wordpress-精确文本修剪功能的主要内容,如果未能解决你的问题,请参考以下文章

使用 Wordpress 修剪 MySQL 中的空格

Silverlight:带有文本修剪功能的按钮模板

使用带有拆分到文本功能的修剪

修剪mp3文件时ffmpeg不精确

用户角色 - 添加角色功能 php 片段 - Wordpress

WordPress - 代码片段插件