为了有助于网站seo,typecho如何直接替换文章内容的友链,直接附代码:
$Keywordspress = new Typecho_Widget_Helper_Form_Element_Textarea('Keywordspress', NULL, NULL, _t('关键字内链'), _t('每行1组以"关键词|(半角竖线)链接"形式填写)')); $form->addInput($Keywordspress); /** * 文章内容替换为内链 */ function get_glo_keywords($content){ $settings = Helper::options()->Keywordspress; $keywords_list = array(); if (strpos($settings,'|')) { //解析关键词数组 $kwsets = array_filter(preg_split("/(\r|\n|\r\n)/",$settings)); foreach ($kwsets as $kwset) { $keywords_list[] = explode('|',$kwset); } } ksort($keywords_list); //对关键词排序,短词排在前面 if($keywords_list){ $readnum = 0; $i = 0; $j = 1; foreach ($keywords_list as $key => $val) { $title = $val[$i]; $len = strlen($title); $str = '<a href="'.$val[$j].'" target="_blank">@'.$title.'</a>'; $str_index = mb_strpos($content, $title); $content = preg_replace('/(?!<[^>]*)'.$title.'(?![^<]*>)/',$str,$content,1); if(is_numeric($str_index)){ $readnum += 1; //$content = substr_replace($content,$str,$str_index,$len); //$content = $this->str_replace_limit($title,$str,$content,$this->limit); } if($readnum == 8) { return $content; //匹配到8个关键词就退出 $i += 2; $j += 2; } } } return $content; }
标签: explode, preg_replace, str_replace, typecho
上面是“typecho如何替换文章内容的友链”的全面内容,想了解更多关于 seo教程 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_2072.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!