Rumah > Soal Jawab > teks badan
我想提取html中的img的src中的内容,匹配是否有img,如果有全部的src都提取出来,请大神赐教。(用java处理)
这个是测试图片1<img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_hahaha.png" alt="">
这个是测试图片2<img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_lalala.png" alt="">
大家讲道理2017-04-18 10:53:26
Ungkapan biasa untuk dilaksanakan, sudah tentu saya menggunakan php
bahasa untuk melaksanakan
$body = '<img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_hahaha.png" alt=""><img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_lalala.png" alt="">';
$imgreg = "/<img src=\"(.*?)\"/";
if(preg_match_all($imgreg, $body, $matches)){
var_dump($matches[1]);
}
PHP中文网2017-04-18 10:53:26
Tukar kod di atas kepada js
var body = '<img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_hahaha.png" alt=""><img src="file:///storage/emulated/0/DCIM/Screenshots/Screenshot_lalala.png" alt="">'
var sources = []
var imgReg = /<img src=\"(.*?)\"/g
var match
while((match = imgReg.exec(body))){
sources.push(match[1])
}
console.log(sources)