【问题标题】:how to remove img link and replace it如何删除img链接并替换它
【发布时间】:2013-01-09 13:28:34
【问题描述】:

我想将我所有的 wordpress 帖子图片链接链接到:http://www.simafun.com 除了一些图片。

所以我使用查找此代码:

<?php
function wpguy_linked_image($content){

    $searchfor = '/(<img[^>]*\/>)/';
    $replacewith = '<a target="_blank" href="'.get_permalink().'">$1</a>';

    {
        $content = preg_replace($searchfor, $replacewith, $content, -1);
    }
    return $content;
}

add_filter('the_content', 'wpguy_linked_image');
?>

它替换所有图片链接,但不删除图片的上一个链接。

  1. 我首先删除上一个链接。例如 : 我的图像链接到自身 “http://www.up.simafun.com/2013/01/police-tabriz-1.jpg” 然后用我的网站名称(http://www.simafun.com)

  2. 我想从更改链接中排除一些图片,例如链接到下载的图片(例如:“http://up.simafun.com/download-simafun.com.gif”)

对不起,我的英语不好。

【问题讨论】:

    标签: php wordpress preg-replace


    【解决方案1】:

    就用这个吧:

    $html = preg_replace("/<img.*src="(.*?)".*\/?>/",'<img src="http://up.simafun.com/download-simafun.com.gif">',$html );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 2019-03-29
      • 2018-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多