Discuz!大师网

搜索
查看: 2784|回复: 3

Discuz!教程之帖子摘要(简介)截取函数messagecutstr()详解

[复制链接]
发表于 2017-9-6 22:10:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
当我们在二次开发Discuz的时候,经常需要调用帖子的摘要或者简介,这里可以使用Discuz自带的内容处理函数messagecutstr()来处理:
函数定义位置:\source\function\function_post.php
使用前请添加 include_once libfile('function/post');
来引入函数
messagecutstr($str, $length, $dot)
参数解释:
$str           要处理的字符串对象
$length     要保留的长度
$dot         超出部分用什么代替

该函数具体定义如下:
  1. function messagecutstr($str, $length = 0, $dot = ' ...') {
  2.         global $_G;
  3.         $str = messagesafeclear($str);
  4.         $sppos = strpos($str, chr(0).chr(0).chr(0));
  5.         if($sppos !== false) {
  6.                 $str = substr($str, 0, $sppos);
  7.         }
  8.         $language = lang('forum/misc');
  9.         loadcache(array('bbcodes_display', 'bbcodes', 'smileycodes', 'smilies', 'smileytypes', 'domainwhitelist'));
  10.         $bbcodes = 'b|i|u|p|color|size|font|align|list|indent|float';
  11.         $bbcodesclear = 'email|code|free|table|tr|td|img|swf|flash|attach|media|audio|groupid|payto'.($_G['cache']['bbcodes_display'][$_G['groupid']] ? '|'.implode('|', array_keys($_G['cache']['bbcodes_display'][$_G['groupid']])) : '');
  12.         $str = strip_tags(preg_replace(array(
  13.                         "/\[hide=?\d*\](.*?)\[\/hide\]/is",
  14.                         "/\[quote](.*?)\[\/quote]/si",
  15.                         $language['post_edit_regexp'],
  16.                         "/\[url=?.*?\](.+?)\[\/url\]/si",
  17.                         "/\[($bbcodesclear)=?.*?\].+?\[\/\\1\]/si",
  18.                         "/\[($bbcodes)=?.*?\]/i",
  19.                         "/\[\/($bbcodes)\]/i",
  20.                 ), array(
  21.                         "[b]$language[post_hidden][/b]",
  22.                         '',
  23.                         '',
  24.                         '\\1',
  25.                         '',
  26.                         '',
  27.                         '',
  28.                 ), $str));
  29.         if($length) {
  30.                 $str = cutstr($str, $length, $dot);
  31.         }
  32.         $str = preg_replace($_G['cache']['smilies']['searcharray'], '', $str);
  33.         if($_G['setting']['plugins']['func'][HOOKTYPE]['discuzcode']) {
  34.                 $_G['discuzcodemessage'] = & $str;
  35.                 $param = func_get_args();
  36.                 hookscript('discuzcode', 'global', 'funcs', array('param' => $param, 'caller' => 'messagecutstr'), 'discuzcode');
  37.         }
  38.         return trim($str);
  39. }
复制代码


点评

海!外直播 cutt.us/88f 禁闻视频 v.ht/nndd 一个社会如果只能靠删除不同看法去维护统一思想的宣传,那就证明这个思想宣传已经到了弱不经风的程度了。看这个就知道..  发表于 2021-8-3 14:38
回复 马甲回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|网站地图|小黑屋|展会网|Discuz站长论坛 |天天打卡

GMT+8, 2024-4-30 21:29 , Processed in 0.027459 second(s), 9 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表