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

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

WBOY
WBOYOriginal
2016-05-25 16:42:351543Durchsuche

<?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/ "
        )
    );
}


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn