在php中使用strip_tags时出现问题 [英] Problem using strip_tags in php
本文介绍了在php中使用strip_tags时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用strip_tags从文本中删除了html标签。
示例
< h1>文章标题< / h1> ;< div class =body>内容在这里......< / div>
输出
文章标题内容在这里......
如果看到输出标题和正文加入(articleThe)。如果标签已被删除,我想插入一个空格。这是可能的。
感谢任何帮助。
谢谢。
解决方案
如果您只想添加一个开始标签直接跟随结束标签的空间,您可以这样做: / p>
$ html = preg_replace('/(< \ / [^>] +?>)(< [ ^> \ /] [^>] *?>)/','$ 1 $ 2',$ html);
$ html = strip_tags($ html);
I have used strip_tags to remove html tags from the text.
Example
<h1>title of article</h1><div class="body">The content goes here......</div>
outputs
title of articleThe content goes here......
If you see the output title and body are joined(articleThe). I want to insert a space if the tag has been removed. Is this possible.
I appreciate any help.
Thanks.
解决方案
If all you want is to add a space where an opening tag directly follows a closing tag, you could do this:
$html = preg_replace('/(<\/[^>]+?>)(<[^>\/][^>]*?>)/', '$1 $2', $html);
$html = strip_tags($html);
这篇关于在php中使用strip_tags时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文