<?php
$str = '<img src="http://img01.feiniu.com/images/show/detail/image/20141031/9b3bbc368d367723bbe5f755b4ce34b3.png" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/d67bcb91fed102dfcbc53946ff1435aa.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/61ee3f9da9652b7ad72a5ccfeab5f731.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/b023abffcee249558d23aafdfa32c4e6.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/c2543cca0b124b9932cd9aee1c0654f0.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/94f0bca937d9a595027daebf4ee9bb00.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/ae3bc1b541929d4653585657eadaff9a.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/8046db84706a16c7deb22045fcfc0230.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/5a968cddcbbe9a61f771fc2cabdce86f.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/ecdc381a3880a3adc04161f108f04f28.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/3a7f38f5b28da9c7643f7d6c228c624e.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/9acd5c96be6e4a591b1e18c8010c38ca.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/1df6a35c80b24f0a5cf5b5812ae401ac.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/5ee9e6614624fdae8230b4fab0f347cd.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/4fdcfee6e45f89204378a3427af2f2bf.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/23114a142ad3f0020f92107ad172689f.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/7f0101d1c37b2769c4217009eaa3d98b.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/be29031fa929f6ca2444a86b06b9ed05.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/48cb07821cec53a1de3cc54cfe3be40b.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/0805eb0a253c70349147e67d2d67e02d.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/c28e7c4d9adf828ea7fef97365a973cd.jpg" alt="" /><img src="http://img01.feiniu.com/C/show/detail/image/20141031/37400542cac93827c842efc3f9c63f04.jpg" alt="" />111<img src="http://img01.feiniu.com/C/show/detail/image/20141031/0b5ca6047c3b9de6e1d53c864e74af16.jpg" alt="" />';
function test($matches){
preg_match_all('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$matches[0],$match,PREG_PATTERN_ORDER);
$imgList = &$match[0];
if($imgList && is_array($imgList)){
foreach($imgList as &$img){
preg_match('/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i', $img, $sub);
$url = $sub[1];
$parseUrl = parse_url($url);
if(strpos($parseUrl['host'], 'feiniu.com') !== false && !preg_match('/^\/images/', $parseUrl['path'])){
$img = preg_replace('/(<img.+src=\"?.+)(\.(jpg|gif|bmp|bnp|png)\"?.+>)/i', "\${1}_800x0\${2}", $img);
}
}
}
return implode("", $imgList);
}
echo preg_replace_callback('/<img.+src=\"?.+\.(jpg|gif|bmp|bnp|png)\"?.+>/i', "test", $str);