php 正则表达式 截取字符串
php正则表达式截取<imgheight=\"88\"width=\"139\"alt=\"\"src=\"...
php 正则表达式 截取 <img height=\"88\" width=\"139\" alt=\"\" src=\"/do/admin/upload/news_image/kk0.jpg\" /></p> <p> </p> <p><img style=\"width: 424px; height: 205px\" alt=\"\" src=\"/do/admin/upload/news_image/kk3.bmp\" /></p> 字符串,把里面的地址截取出来返回数组,例如把do/admin/upload/news_image/kk3.bmp截取出来 注意!do前面的/是不要的
展开
1个回答
展开全部
<?php
$str
=
"<img
height=\"88\"
width=\"139\"
alt=\"\"
src=\"/do/admin/upload/news_image/kk0.jpg\"
/></p><p>
</p><p><img
style=\"width:
424px;
height:
205px\"
alt=\"\"
src=\"/do/admin/upload/news_image/kk3.bmp\"
/></p><img
height=\"88\"
width=\"139\"
alt=\"\"
src=\"/do/admin/upload/news_image/kk0.jpg\"
/></p><p>
</p><p><img
style=\"width:
424px;
height:
205px\"
alt=\"\"
src='/do/admin/upload/news_image/kk3.bmp'
/></p>";
$reg
=
'/\ssrc=[\'\"][\\/]([^\'"]*)[\'\"]\s/i';
preg_match_all($reg
,
$str
,
$out_ary);
//这个数组就是地址
$src_ary
=
$out_ary[1];
dump($out_ary);
dump($src_ary);
//格式化打印变量
function
dump($uStr){
echo
"<pre>";
var_dump($uStr);
echo
"</pre>";
}
?>
$str
=
"<img
height=\"88\"
width=\"139\"
alt=\"\"
src=\"/do/admin/upload/news_image/kk0.jpg\"
/></p><p>
</p><p><img
style=\"width:
424px;
height:
205px\"
alt=\"\"
src=\"/do/admin/upload/news_image/kk3.bmp\"
/></p><img
height=\"88\"
width=\"139\"
alt=\"\"
src=\"/do/admin/upload/news_image/kk0.jpg\"
/></p><p>
</p><p><img
style=\"width:
424px;
height:
205px\"
alt=\"\"
src='/do/admin/upload/news_image/kk3.bmp'
/></p>";
$reg
=
'/\ssrc=[\'\"][\\/]([^\'"]*)[\'\"]\s/i';
preg_match_all($reg
,
$str
,
$out_ary);
//这个数组就是地址
$src_ary
=
$out_ary[1];
dump($out_ary);
dump($src_ary);
//格式化打印变量
function
dump($uStr){
echo
"<pre>";
var_dump($uStr);
echo
"</pre>";
}
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询