Problem using strip_tags in php [duplicate]

风流意气都作罢 提交于 2019-11-27 03:22:23

问题


This question already has an answer here:

  • strip_tags() … replace tags by space rather than deleting them 10 answers

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.


回答1:


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);


来源:https://stackoverflow.com/questions/4482152/problem-using-strip-tags-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!