Regex删除从某个标签开始并在另一个标签结束的所有内容


Regex remove everything starting from some tag and ends at some other tag

我有一个字符串,如下

<img alt="rlogo" src="https://something.net/logo.gif/resized_logo.png?r=3" />
<p>
  <strong>Headquarters:</strong> Austin, TX
  <br /><strong>URL:</strong> <a href="https://something.com/F402B805CC">https://something.com/j/F402B805CC</a>
</p>
Lorem ipsum dollar sit amet  

我想删除除"Lorem ipsum美元坐amet"以外的所有内容,到目前为止,我设法使用删除了图像标签

preg_replace('<img alt='"rlogo'".*>','',$description)

但这对<p>标签不起作用,因为<p>标签后面有新行。

有什么方法可以删除从<img</a></p>的所有

使用s选项(点匹配换行符);

$result = preg_replace('%<img.*?</p>%si', '', $description);

Regex Explanation

<img.*?</p>
Options: Case insensitive (i); Exact spacing; Dot matches line breaks (s); ^$ don’t match at line breaks; Greedy quantifiers; Regex syntax only
Match the character string “<img” literally (case insensitive) «<img»
Match any single character «.*?»
   Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the character string “</p>” literally (case insensitive) «</p>»