|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
当我们在二次开发Discuz的时候,经常需要调用帖子的摘要或者简介,这里可以使用Discuz自带的内容处理函数messagecutstr()来处理:
函数定义位置:\source\function\function_post.php
使用前请添加 include_once libfile('function/post');
来引入函数
messagecutstr($str, $length, $dot)
参数解释:
$str 要处理的字符串对象
$length 要保留的长度
$dot 超出部分用什么代替
该函数具体定义如下:
- function messagecutstr($str, $length = 0, $dot = ' ...') {
- global $_G;
- $str = messagesafeclear($str);
- $sppos = strpos($str, chr(0).chr(0).chr(0));
- if($sppos !== false) {
- $str = substr($str, 0, $sppos);
- }
- $language = lang('forum/misc');
- loadcache(array('bbcodes_display', 'bbcodes', 'smileycodes', 'smilies', 'smileytypes', 'domainwhitelist'));
- $bbcodes = 'b|i|u|p|color|size|font|align|list|indent|float';
- $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']])) : '');
- $str = strip_tags(preg_replace(array(
- "/\[hide=?\d*\](.*?)\[\/hide\]/is",
- "/\[quote](.*?)\[\/quote]/si",
- $language['post_edit_regexp'],
- "/\[url=?.*?\](.+?)\[\/url\]/si",
- "/\[($bbcodesclear)=?.*?\].+?\[\/\\1\]/si",
- "/\[($bbcodes)=?.*?\]/i",
- "/\[\/($bbcodes)\]/i",
- ), array(
- "[b]$language[post_hidden][/b]",
- '',
- '',
- '\\1',
- '',
- '',
- '',
- ), $str));
- if($length) {
- $str = cutstr($str, $length, $dot);
- }
- $str = preg_replace($_G['cache']['smilies']['searcharray'], '', $str);
- if($_G['setting']['plugins']['func'][HOOKTYPE]['discuzcode']) {
- $_G['discuzcodemessage'] = & $str;
- $param = func_get_args();
- hookscript('discuzcode', 'global', 'funcs', array('param' => $param, 'caller' => 'messagecutstr'), 'discuzcode');
- }
- return trim($str);
- }
复制代码
|
|