如何提取字符串中的图片地址并转换编码后放回原处?
本帖最后由 dz215136304 于 2012-06-27 12:05:34 编辑
字符串:<br tangram-key="module-split" style="display: none;"><br style="display: none;"><br style="display: none;"><p><img src="http://img02.taobaocdn.com/imgextra/i2/733163714/T2gStjXhhNXXXXXXXX_!!733163714.jpg"><img src="http://img01.taobaocdn.com/imgextra/i1/733163714/T2ISpiXg4NXXXXXXXX_!!733163714.jpg"><img src="http://img03.taobaocdn.com/imgextra/i3/733163714/T2LVX3XdVcXXXXXXXX_!!733163714.jpg"><img src="http://img01.taobaocdn.com/imgextra/i1/733163714/T2.6xMXXNcXXXXXXXX_!!733163714.jpg"><img src="http://img01.taobaocdn.com/imgextra/i1/733163714/T25.tiXiBNXXXXXXXX_!!733163714.jpg"><img src="http://img03.taobaocdn.com/imgextra/i3/733163714/T2DF0NXlVbXXXXXXXX_!!733163714.jpg"><img src="http://img04.taobaocdn.com/imgextra/i4/733163714/T2gqXNXetcXXXXXXXX_!!733163714.jpg"><img src="http://img01.taobaocdn.com/imgextra/i1/733163714/T2V00NXcXdXXXXXXXX_!!733163714.jpg"><img src="http://img04.taobaocdn.com/imgextra/i4/733163714/T2jglOXoBcXXXXXXXX_!!733163714.jpg"><img src="http://img04.taobaocdn.com/imgextra/i4/733163714/T2TCRiXhhNXXXXXXXX_!!733163714.jpg"><img src="http://img02.taobaocdn.com/imgextra/i2/733163714/T2SydKXcNcXXXXXXXX_!!733163714.jpg"><img src="http://img04.taobaocdn.com/imgextra/i4/733163714/T2f0VOXg0dXXXXXXXX_!!733163714.jpg"><img src="http://img01.taobaocdn.com/imgextra/i1/733163714/T2t0RkXlNNXXXXXXXX_!!733163714.jpg"></p><p> </p>
能将里面的 所有图片地址全部提取出来,然后将图片地址通过已经写好的静态方法 encodeimg 转码后,再放回原处
static function encodeimg($str,$suffix='.jpg_310x310.jpg'){
$prvestr=rand(0,9);
$endstr=rand(0,9);
$str=substr($str,0,-4).$suffix;
$str=base64_encode($str);
$str=$prvestr.$str.$endstr; return $str;
}
------解决方案--------------------回调函数 如果是类的方法的话,需要用数组形式传递