【发布时间】:2016-09-06 16:06:09
【问题描述】:
我有这样的东西:
$string = '<some code before><div class="abc">Something written here</div><some other code after>'
我想要的是获取 div 中的内容并输出:
Something written here
我如何在 php 中做到这一点?提前致谢!
【问题讨论】:
-
echo strip_tags($string); -
仅使用 strip_tags() 可能还会留下一些
<other code>s 的内容... -
@BlueBockser 没有更详细的问题,我们不知道
<some code before>是否包含将要留下的内容.... 就问题而言,它没有 -
正如所写,
和 包含必须删除且未显示的代码。 -
正如所写,
<some code before>和<some other code after>将被strip_tags()完全删除....如果<some other code after>实际上是<div>some more text</div>, then一些更多的文本将被保留