this:替换<a /> tag with its src attribute that have another attribute
$text = '<img class="fruit" src="http://exmple.com/apple.png" id="apple"><BR>
<img class="fruit" src="http://exmple.com/Lemon.png" ><BR>
<img src="http://exmple.com/banana.png" class="fruit"><BR>';
$pattern = '/<img(.*) src="([^"].*)"(.*)\>/i'; //<--the problem
$replace = preg_replace($pattern, '$2', $text);
echo $replace;
give me:
http://exmple.com/apple.png" id="apple
http://exmple.com/lemon.png
http://exmple.com/banana.png" class="fruit
All I need just replace them with their src
value; like this:
http://exmple.com/apple.png
http://exmple.com/lemon.png
http://exmple.com/banana.png
Got hours on codepad,但仍然没有所需$pattern
;我之前得到了similiar question,但没有工作;我在逻辑上并不擅长,所以我需要帮助。
$模式= '' 让我知道这是否正常工作.. – 2013-04-04 04:27:09
岂不DOM解析器像['DOMDocument'(http://php.net/manual/en/class。 domdocument.php)是一个更好的解决方案来刮'src'es? – 2013-04-04 04:28:40
你能澄清你想要的吗?你想删除图片标签,并用src字符串替换它们? – loganfsmyth 2013-04-04 04:29:04