且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在php中使用strip_tags时出现问题

更新时间:2023-09-11 22:23:40

如果您只想添加一个开始标签直接跟随结束标签的空间,您可以这样做: / 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);