我想刪除所有img標籤的字符串,如果不`噸喜歡我的形式,但我不能正則表達式查找所有img標籤不和取出
例子(我想留在我的字符串):
<img src="http://localhost/uploads/user1/test3.jpg" title="test" class="img-responsive img-maxheight">
<img src="http://localhost/uploads/user2/test1.jpg" alt="test" class="img-responsive img-maxheight">
<img src="http://localhost/uploads/user3/test2.jpg" class="img-responsive img-maxheight">
,並在PHP我正則表達式的代碼是:
$pattern ="/<img src=\"http:\/\/localhost\/(uploads|thumbs)\/$user\/(.*?)\" (alt|title|)=\"(.*?)\" class=\"img-responsive img-maxheight\">/i";
$replacement = ' ';
$content = preg_replace($pattern, $replacement, $content);
爲什麼使用正則表達式? ? – Akintunde007
[RegEx match open tags not except XHTML self-contained tags]可能重複(http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Pharaoh