咱们好,我是dedecms51网技能协助今日给咱们剖析下当咱们在二次开发Discuz的时分,需求运用到调用简介的时分,能够运用Discuz自带的内容处理函数
messagecutstr($str, $length, $dot)

参数解说:
$str 要处理的字符串目标
$length 要保存的长度
$dot 超出部分用什么替代

举例:
<div>$str = 'DZ起点网便是好,学习Dsicuz少不了!';</div><div>$length = 8;</div><div>$dot = '+更多Discuz教程请百度查找“DZ起点网”!';</div><div>
</div><div>echo messagecutstr($str, $length, $dot);</div>

如图:
此时会输出
DZ起点网+更多Discuz教程请百度查找“DZ起点网”!

如图:



特别声明,假如你运用messagecutstr()函数不起作用时,不放试试将
include_once libfile('function/post');
这段代码引进,由于你messagecutstr()函数是在“function/post”中界说的!

messagecutstr()完好的函数界说如下:
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);
}
仿制代码

声明:有的资源均来自网络转载,版权归原作者所有,如有侵犯到您的权益 请联系邮箱:123456@qq.com 我们将配合处理!

原文地址:discuz字符串截取函数messagecutstr()详解发布于2023-03-03 17:27:02

相关推荐