我在数据库中存储了以这种格式存储的图像
$link = this is my photo <img data-liked='0' data-reblogged='0' data-attachment-id="299971" data-medium-file="http://my.files.wordpress.com/2013/12/img_6697.png?w=394" width="73" height="130" src="http://my.files.wordpress.com/2013/12/img_6697.png?w=73&h=130" class="attachment-thumbnail" alt="IMG_6697" />, school photo;
如果可以获得输出
,我很想 this is my photo <img src="http://my.files.wordpress.com/2013/12/img_6697.png?w=73&h=130" />, school photo
只是图片来源没有别的......
我试过这个并获得了图片网址,但我需要以上结果
$str = preg_replace('#<img.+?src=[\'"]([^\'"]+)[\'"].+/>#i', "$1", $link);
echo $str;
答案 0 :(得分:1)
$str = preg_replace('#<img.*?src="(.*?)".*?\/>#i', "<img src=\"$1\" />", $link);
echo $str;
您可能希望保留alt:
$str = preg_replace('#<img.*?src="(.*?)".*?alt="(.*?)".*?\/>#i', "<img src=\"$1\" alt=\"$2\" />", $link);
echo $str;