21,886
社区成员
发帖
与我相关
我的任务
分享
$body =<<< TXT
<img src="\"http://p1.pstatp.com/large/1b7500018624e6abe178\"" img_width="\"505\"" img_height="\"309\"" alt="\"马云与同学吃饭出场方式让人意外" 十年聚会成马云的独角戏\"="" style="\"border:" 0px;="" max-width:="" 100%;="" display:="" block;="" margin:="" 10px="" auto;\"="">
TXT;
preg_match_all('/(?<=src=)\S+/', $body, $m);
print_r($m);
Array
(
[0] => Array
(
[0] => "\"http://p1.pstatp.com/large/1b7500018624e6abe178\""
)
)
但由于你的画蛇添足,这已经不是 url 了<html>
<head>
</head>
<body>
<img id="s" src="https://ss0.baidu.com/73F1bjeh1BF3odCf/it/u=2136081071,3185426567&fm=73">
<script>
alert('ss');
var ss = document.getElementById('s').src;
alert(ss);
</script>
</body>
</html>
这样?
$body='<p>中国。<img src="http://p31.pstatp.com/large/2a4300005da227b88e87" img_width="448" img_height="252" inline="0" style="border: 0px; max-width: 100%; display: block; margin: 10px auto;"/></p><p>在古代';
preg_match_all('#<img\s*src="([^"]+?)"[^/]*?/>#',$body,$m);
print_r($m[1]);
/*
Array
(
[0] => http://p31.pstatp.com/large/2a4300005da227b88e87
)
*/