本节主要内容:
PHP替换文章内链的函数,php关键词替换,屏蔽与还原原始链接。
代码:
<?php
/*
* PHP替换文章内链
* by www.jb200.com
*/
function _base64_encode($t,$str) {
return $t.""".base64_encode($str).""";
}
function _base64_decode($t,$str) {
return $t.""".base64_decode($str).""";
}
function _keylinks($txt, $replacenum = '',$link_mode = 1) {
/* 屏蔽原始的 a */
$replace_a = "_base64_encode('ori_a=',' ')";
$replace1_a = "stripslashes(base64_decode('1'))";
$search_a = "/<a.*?>.*?</a>/isxe";
$search1_a = "/ori_a=(".*?")/isxe";
$txt = preg_replace($search_a, $replace_a, $txt);
/* 屏蔽alt title src */
$search = "/(alts*=s*|titles*=s*|srcs*=s*) # find <a href=
(["'])?(.*?) # find single or double quote
(?(2)2|s+?) # if quote found, match up to next matching
# quote, otherwise match up to next space
/isxe";
$replace = "_base64_encode('1','3')";
$replace1 = "_base64_decode('1','3')";
$txt = preg_replace($search, $replace, $txt);
echo $txt;
echo "<br>http://www.jb200.com/<br><br><br><br>";
/*
$keywords = $this->data['keywords'];
if($keywords) $keywords = strpos(',',$keywords) === false ? explode(' ',$keywords) : explode(',',$keywords);
if($link_mode && !empty($keywords)) {
foreach($keywords as $keyword) {
$linkdatas[] = $keyword;
}
} else {
$linkdatas = getcache('keylink','commons');
}
if($linkdatas) {
$word = $replacement = array();
foreach($linkdatas as $v) {
if($link_mode && $keywords) {
$word1[] = '/'.preg_quote($v, '/').'/';
$word2[] = $v;
$replacement[] = '<a href="javascript:;" onclick="show_ajax(this)" class="keylink">'.$v.'</a>';
} else {
$word1[] = '/'.preg_quote($v[0], '/').'/';
$word2[] = $v[0];
$replacement[] = '<a href="'.$v[1].'" target="_blank" class="keylink">'.$v[0].'</a>';
}
}
if($replacenum != '') {
$txt = preg_replace($word1, $replacement, $txt, $replacenum);
} else {
$txt = str_replace($word2, $replacement, $txt);
}
}
*/
/* 还原原始 a */
$txt = preg_replace($search1_a, $replace1_a, $txt);
/* 还原alt title src */
$txt = preg_replace($search, $replace1, $txt);
echo $txt;
return $txt;
}
$con = "<P> <STRONG> 性生活过度伤害前列腺。和谐<a href=asdf.htm >美满的性生</a>活,是男<a href='/dssd.aosdfj'>女生理的天</a>然需要,是夫妻感情的粘合剂之一,是夫妻<a href="wef.html">生活必不少的重</a>要组成部分。但是有此想法的夫妻可要注意了。因为做x爱时间并非越长越好,夫妻的性生活的和谐与美满也不由性xai时间的长短来决定。反而,超时性XZ爱,还会影响到夫妻的健康,甚至引发各种疾病。</STRONG></P>
<P align=center><IMG height=334 alt=性生活过度伤害前列腺 title="枯地枯要要要要极有人" title='sodksokdjfoisjdfj' src="/Files/前列腺/前列腺增生不手术的严重后果.jpg" width=341 border=0></P>";
_keylinks($con);
?>