• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP filter_save_tags函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中filter_save_tags函数的典型用法代码示例。如果您正苦于以下问题:PHP filter_save_tags函数的具体用法?PHP filter_save_tags怎么用?PHP filter_save_tags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了filter_save_tags函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: filter_phrases

/**
 * Process phrases intelligently found within a HTML text (such as adding links).
 *
 * @staticvar array $usedpharses
 * @param string $text             the text that we are filtering
 * @param array $link_array       an array of filterobjects
 * @param array $ignoretagsopen   an array of opening tags that we should ignore while filtering
 * @param array $ignoretagsclose  an array of corresponding closing tags
 * @param bool $overridedefaultignore True to only use tags provided by arguments
 * @return string
 **/
function filter_phrases($text, &$link_array, $ignoretagsopen = NULL, $ignoretagsclose = NULL, $overridedefaultignore = false)
{
    global $CFG;
    static $usedphrases;
    $ignoretags = array();
    // To store all the enclosig tags to be completely ignored.
    $tags = array();
    // To store all the simple tags to be ignored.
    if (!$overridedefaultignore) {
        // A list of open/close tags that we should not replace within
        // Extended to include <script>, <textarea>, <select> and <a> tags
        // Regular expression allows tags with or without attributes
        $filterignoretagsopen = array('<head>', '<nolink>', '<span class="nolink">', '<script(\\s[^>]*?)?>', '<textarea(\\s[^>]*?)?>', '<select(\\s[^>]*?)?>', '<a(\\s[^>]*?)?>');
        $filterignoretagsclose = array('</head>', '</nolink>', '</span>', '</script>', '</textarea>', '</select>', '</a>');
    } else {
        // Set an empty default list.
        $filterignoretagsopen = array();
        $filterignoretagsclose = array();
    }
    // Add the user defined ignore tags to the default list.
    if (is_array($ignoretagsopen)) {
        foreach ($ignoretagsopen as $open) {
            $filterignoretagsopen[] = $open;
        }
        foreach ($ignoretagsclose as $close) {
            $filterignoretagsclose[] = $close;
        }
    }
    // Invalid prefixes and suffixes for the fullmatch searches
    // Every "word" character, but the underscore, is a invalid suffix or prefix.
    // (nice to use this because it includes national characters (accents...) as word characters.
    $filterinvalidprefixes = '([^\\W_])';
    $filterinvalidsuffixes = '([^\\W_])';
    // Double up some magic chars to avoid "accidental matches"
    $text = preg_replace('/([#*%])/', '\\1\\1', $text);
    //Remove everything enclosed by the ignore tags from $text
    filter_save_ignore_tags($text, $filterignoretagsopen, $filterignoretagsclose, $ignoretags);
    // Remove tags from $text
    filter_save_tags($text, $tags);
    // Time to cycle through each phrase to be linked
    $size = sizeof($link_array);
    for ($n = 0; $n < $size; $n++) {
        $linkobject =& $link_array[$n];
        // Set some defaults if certain properties are missing
        // Properties may be missing if the filterobject class has not been used to construct the object
        if (empty($linkobject->phrase)) {
            continue;
        }
        // Avoid integers < 1000 to be linked. See bug 1446.
        $intcurrent = intval($linkobject->phrase);
        if (!empty($intcurrent) && strval($intcurrent) == $linkobject->phrase && $intcurrent < 1000) {
            continue;
        }
        // All this work has to be done ONLY it it hasn't been done before
        if (!$linkobject->work_calculated) {
            if (!isset($linkobject->hreftagbegin) or !isset($linkobject->hreftagend)) {
                $linkobject->work_hreftagbegin = '<span class="highlight"';
                $linkobject->work_hreftagend = '</span>';
            } else {
                $linkobject->work_hreftagbegin = $linkobject->hreftagbegin;
                $linkobject->work_hreftagend = $linkobject->hreftagend;
            }
            // Double up chars to protect true duplicates
            // be cleared up before returning to the user.
            $linkobject->work_hreftagbegin = preg_replace('/([#*%])/', '\\1\\1', $linkobject->work_hreftagbegin);
            if (empty($linkobject->casesensitive)) {
                $linkobject->work_casesensitive = false;
            } else {
                $linkobject->work_casesensitive = true;
            }
            if (empty($linkobject->fullmatch)) {
                $linkobject->work_fullmatch = false;
            } else {
                $linkobject->work_fullmatch = true;
            }
            // Strip tags out of the phrase
            $linkobject->work_phrase = strip_tags($linkobject->phrase);
            // Double up chars that might cause a false match -- the duplicates will
            // be cleared up before returning to the user.
            $linkobject->work_phrase = preg_replace('/([#*%])/', '\\1\\1', $linkobject->work_phrase);
            // Set the replacement phrase properly
            if ($linkobject->replacementphrase) {
                //We have specified a replacement phrase
                // Strip tags
                $linkobject->work_replacementphrase = strip_tags($linkobject->replacementphrase);
            } else {
                //The replacement is the original phrase as matched below
                $linkobject->work_replacementphrase = '$1';
            }
//.........这里部分代码省略.........
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:101,代码来源:filterlib.php


示例2: break_up_long_words

/**
 * Given some normal text this function will break up any
 * long words to a given size by inserting the given character
 *
 * It's multibyte savvy and doesn't change anything inside html tags.
 *
 * @param string $string the string to be modified
 * @param int $maxsize maximum length of the string to be returned
 * @param string $cutchar the string used to represent word breaks
 * @return string
 */
function break_up_long_words($string, $maxsize = 20, $cutchar = ' ')
{
    /// Loading the textlib singleton instance. We are going to need it.
    $textlib = textlib_get_instance();
    /// First of all, save all the tags inside the text to skip them
    $tags = array();
    filter_save_tags($string, $tags);
    /// Process the string adding the cut when necessary
    $output = '';
    $length = $textlib->strlen($string);
    $wordlength = 0;
    for ($i = 0; $i < $length; $i++) {
        $char = $textlib->substr($string, $i, 1);
        if ($char == ' ' or $char == "\t" or $char == "\n" or $char == "\r" or $char == "<" or $char == ">") {
            $wordlength = 0;
        } else {
            $wordlength++;
            if ($wordlength > $maxsize) {
                $output .= $cutchar;
                $wordlength = 0;
            }
        }
        $output .= $char;
    }
    /// Finally load the tags back again
    if (!empty($tags)) {
        $output = str_replace(array_keys($tags), $tags, $output);
    }
    return $output;
}
开发者ID:hatone,项目名称:moodle,代码行数:41,代码来源:weblib.php



注:本文中的filter_save_tags函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP filter_set_applies_to_strings函数代码示例发布时间:2022-05-15
下一篇:
PHP filter_save_ignore_tags函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap