web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

typecho如何替换文章内容的友链

381 ℃
     

为了有助于网站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;
}

php语法如何去除空格和符号

php语法如何替换数组中的字符串

php语法如何实现自动替换超链接

php如何去除字符串中多余符号(比如逗号)

php怎么删除字符串中指定字符

标签: explode, preg_replace, str_replace, typecho

上面是“typecho如何替换文章内容的友链”的全面内容,想了解更多关于 seo教程 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_2072.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > seo教程
本文共计1122个字,预计阅读时长8分钟
生活小工具,收录了80多款小工具
上一篇: 基于JavaScrip的web动画库——GSAP
下一篇: 免费商用中文字体——优设鲨鱼菲特健康体
x 打工人ai神器