码迷,mamicode.com
首页 > 其他好文 > 详细

替换关键词并过滤特殊标签

时间:2017-01-06 13:02:45      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:seo   base64   targe   run   lex   ref   ase   name   amp   

	public static function parse_related_link($content, $extent) {
		global $_G;
		loadcache(‘relatedlink‘);
		$allextent = array(‘article‘ => 0, ‘forum‘ => 1, ‘group‘ => 2, ‘blog‘ => 3);
		if($_G[‘cache‘][‘relatedlink‘] && isset($allextent[$extent])) {
			$searcharray = $replacearray = array();
			foreach($_G[‘cache‘][‘relatedlink‘] as $link) {
				$link[‘extent‘] = sprintf(‘%04b‘, $link[‘extent‘]);
				if($link[‘extent‘][$allextent[$extent]] && $link[‘name‘] && $link[‘url‘]) {
					$searcharray[$link[name]] = ‘/(‘.preg_quote($link[‘name‘]).‘)/i‘;
					$replacearray[$link[name]] = "<a href=\"$link[url]\" target=\"_blank\" class=\"relatedlink\">$link[name]</a>";
				}
			}
			if($searcharray && $replacearray) {
				$_G[‘trunsform_tmp‘] = array();
				$content = preg_replace("/(<script\s+.*?>.*?<\/script>)|(<a\s+.*?>.*?<\/a>)|(<img\s+.*?[\/]?>)|(\[attach\](\d+)\[\/attach\])/ies", "helper_seo::base64_transform(‘encode‘, ‘<relatedlink>‘, ‘\\1\\2\\3\\4‘, ‘</relatedlink>‘)", $content);
				$content = preg_replace($searcharray, $replacearray, $content, 1);
				$content = preg_replace("/<relatedlink>(.*?)<\/relatedlink>/ies", "helper_seo::base64_transform(‘decode‘, ‘‘, ‘\\1‘, ‘‘)", $content);
			}
		}
		return $content;
	}

  上面是discuz的实现

替换关键词并过滤特殊标签

标签:seo   base64   targe   run   lex   ref   ase   name   amp   

原文地址:http://www.cnblogs.com/jenqz/p/6255711.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!