我有这个内容:
<h1 class="contf _48_black caphead">
<span>The essence of social media is knowing your audience and engaging them in something they love. In real-time, relevance and resonance! </span>
<a href="https://twitter.com/" target="_blank">
<img class="retwt" src="images/retweet.svg">
</a>
<span class="secmov"><img src="images/arrow.svg"></span>
</h1>
我正在尝试从 h1 TAG 中提取内容,如下所示,但无法获取。
<?php
$result = <h1 class="contf _48_black caphead">
<span>The essence of social media is knowing your audience and engaging them in something they love. In real-time, relevance and resonance! </span>
<a href="https://twitter.com/" target="_blank">
<img class="retwt" src="images/retweet.svg">
</a>
<span class="secmov"><img src="images/arrow.svg"></span>
</h1>;
preg_match_all('$<h1(.*?)</h1>$i',$result, $subresult);
print_r($subresult);
?>
其中,如下工作-
preg_match_all('$span>(.*?)</span>$i',$result, $subresult);
有人可以让我吗?
您必须使用 m 选项使点与换行符匹配。
preg_match_all('`<h1(.*?)</h1>`im',$result, $subresult);
但我同意你应该使用 DOMDocument 的评论。
请检查我在下面使用reg_exp
。我希望这正是您正在寻找的。
preg_match_all('/<h1.*?>(.*)<'/h1>/msi',$result, $subresult);
print_r($subresult);