如何删除img链接并替换它

时间:2013-01-09 13:28:34

标签: php wordpress preg-replace

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

所以我使用find this code:

<?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”)

  3. 请原谅我的英语不好。

1 个答案:

答案 0 :(得分:0)

只需使用:

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