如何使用PHP替换字符串中的开始和结束h1标签?
问题描述:
I have captured the <h1>
tag and its inner contents from a webpage and I need to remove the <h1>
and </h1>
parts of the string. The problem is that I won't know if the tag is written as <h1>
or <h1 id="something">
, etc. I know I can write
$tag = str_replace("<h1>", '', $tag);
$tag = str_replace("</h1>", '', $tag);
But how can I handle the more general case, where it may be <h1 id="something">
, or something else?
我从网页上捕获了 但我如何处理更一般的情况,它可能是&lt; h1&gt; code>标签及其内部内容 我需要删除字符串的
&lt; h1&gt; code>和
&lt; / h1&gt; code>部分。 问题是我不知道标签是否写成
&lt; h1&gt; code>或
&lt; h1 id =“something”&gt; code>等。我知道我 可以写 p>
$ tag = str_replace(“&lt; h1&gt;”,'',$ tag);
$ tag = str_replace(“&lt; / h1&gt;”, '',$ tag);
code> pre>
&lt; h1 id =“something”&gt; code>,或者 别的吗? p>
div>