所用的方法有点特别,虽然公司的老程序员也说关联链接冲突不是这么搞滴,但是管他呢,
黑猫白猫抓到老鼠就是好猫
例如:
< a href="www。yyy.com">做<a href="www。yyy.com">程序</a>是件很有意思的事</a>
在浏览器中效果自已试吧,这里不能发链接
看到结果了吗?
很显然这不是我想要的效果,我期望达到的效果是只显示比较“长”的词的链接。
解决方案:
找到 根目录下的
include/global.func.PHP 文件,找到keylinks 函数,将这个函数替换为:
function keylinks($txt,$replacenum = '')
{
$search = "/(alts*=s*|titles*=s*)["|'](.+?)["|']/ise";
$replace = "_base64_encode('1','2')";
$replace1 = "_base64_decode('1','2')";
$txt = preg_replace($search,$replace,$txt);
$linkdatas = cache_read('keylink.PHP','',1);
if($linkdatas)
{
$word = $replacement = array();
foreach($linkdatas as $v)
{
$word1[] = '/'.preg_quote($v[0],'/').'/';
$word2[] = $v[0];
$replacement[] = '<a class="keylink" href="'.$v[1].'" target="_blank">'.$v[0].'</a>';
}
if($replacenum != '')
{
$txt = preg_replace($word1,$replacement,$txt,$replacenum);
}
else
{
$txt = str_replace($word2,$txt);
}
}
$txts = array();
$txts = split('$v){
if($k!=0){
$txts[$k] = '$v){
if(stripos($v,'')){
$counta++;
}else{
if($counta != 1){
$txts[$k] = preg_replace('//',$txts[$k]);
$txts[$k] = preg_replace('/<(/)?a(s+.*?)?>/',$txts[$k],$counta-1,$count);
$counta = $counta-$count;
}
}
}
}
$t = '';
foreach($txts as $v){
$t .= $v;
}
$txt = $t;
$txt = preg_replace($search,$replace1,$txt);
return $txt;
}
{
$search = "/(alts*=s*|titles*=s*)["|'](.+?)["|']/ise";
$replace = "_base64_encode('1','2')";
$replace1 = "_base64_decode('1','2')";
$txt = preg_replace($search,$replace,$txt);
$linkdatas = cache_read('keylink.PHP','',1);
if($linkdatas)
{
$word = $replacement = array();
foreach($linkdatas as $v)
{
$word1[] = '/'.preg_quote($v[0],'/').'/';
$word2[] = $v[0];
$replacement[] = '<a class="keylink" href="'.$v[1].'" target="_blank">'.$v[0].'</a>';
}
if($replacenum != '')
{
$txt = preg_replace($word1,$replacement,$txt,$replacenum);
}
else
{
$txt = str_replace($word2,$txt);
}
}
$txts = array();
$txts = split('$v){
if($k!=0){
$txts[$k] = '$v){
if(stripos($v,'')){
$counta++;
}else{
if($counta != 1){
$txts[$k] = preg_replace('//',$txts[$k]);
$txts[$k] = preg_replace('/<(/)?a(s+.*?)?>/',$txts[$k],$counta-1,$count);
$counta = $counta-$count;
}
}
}
}
$t = '';
foreach($txts as $v){
$t .= $v;
}
$txt = $t;
$txt = preg_replace($search,$replace1,$txt);
return $txt;
}