剥离html标题标签及其内容 - 在php中

时间:2018-06-01 11:48:35

标签: php html tags strip-tags

有没有办法剥离所有h1 h2,h3 ...标签及其内容? 我需要为一项任务获得一份清理过的文本。

另一项任务是在没有html标签的情况下获得第一个h2内容。

这是我原来的副本:

<h2>Title of product</h2> </h3>Subtitle of product</h3> 
Here starts the first paragraph and goes on to the next... 
<h3>Subtitle of the paragraph</h3> Here goes on the second paragraph.

任务1:只获取没有任何html标签及其任何内容的复制文本,如下所示:

Here starts the first paragraph and goes on to the next... 
Here goes on the second paragraph.

任务2:只获取第一个h2-tag的内容,仅此而已:

Title of product
希望你能帮助我。我不知道如何在PHP中这样做。 我知道你可以剥离,但我不知道如何删除(任务2)一个特定的序列。

我对任务1的尝试是这样的:

$copy = trim(preg_replace('/\t+/', '', htmlspecialchars($article->getCopy())))

它无法删除html标记内的内容。

0 个答案:

没有答案
相关问题