Home  >  Article  >  php教程  >  php把内容中图片连接地址替换成自己的

php把内容中图片连接地址替换成自己的

WBOY
WBOYOriginal
2016-05-25 16:42:351575browse

<?php
$files = &#39;<img src="http://img.phprm.com/img/bid_v2/bid_v2_content/p_bid.gif" alt="普通任务" /><img     style="max-width:90%" height="60px" style="padding-top: 10px;" src="http://img.phprm.com/img/index_v3/20100611001.gif" alt="php把内容中图片连接地址替换成自己的 " >&#39;;
// 图片地址转换一下   $p=preg_replace(&#39;//image//&#39;, &#39;http://qq.ip138.com/image/&#39;, $pg[1]);
$reg = "/src\s*=\s*([\&#39;|\"]?[^\s^\&#39;^\"^>]+?[\&#39;|\"]?)/iU";
$img = preg_match_all($reg, $files, $imgs);
for ($i = 0; $i < count($imgs[0]); $i++) {
$pic = trim($imgs[1][$i], &#39;"&#39;."&#39;".&#39; &#39;);
    echo $pic."<br>";
    //保存图片
    $opts = array(
        &#39;http&#39; => array(
            &#39;header&#39; => "referer: http://www.phprm.com/ "
        )
    );
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn