开发者

Problem using strip_tags in php [duplicate]

This question already has answers here: strip_tags() .... replace tags by space rather than deleting them (11 answers) Closed 9 years ago.

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开发者_C百科.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜