This article mainly introduces the solution for PHP to use strip_tags() to remove HTML tags and still have blank spaces. It involves related operation skills of PHP regular replacement. Friends who need it can refer to it.
The example of this article tells about PHP Use strip_tags() to remove html tags and still have blank solutions. Share it with everyone for your reference, the details are as follows:
$subject = strip_tags($newsRs['content']);//去除html标签 $pattern = '/\s/';//去除空白 $content = preg_replace($pattern, '', $subject); $seodata['articledescription'] = mb_substr($content, 0, 80);//截取80个汉字
Note: strip_tags(); in the first step; just replaces the html tags with spaces
For example:
<p> 张志斌张志斌张志斌张志斌张志斌张志 </p> <p> <br /> </p> <p> alsdkjf;laskjd;flasj; </p> <p> asdjfasjd;lkafsj;lfdkj </p> <p> aksdjfl;ak </p>
strip_tags() will become
张志斌张志斌张志斌张志斌张志斌张志 alsdkjf;laskjd;flasj; asdjfasjd;lkafsj;lfdkj aksdjfl;ak
after processing. This may not be what we want, and then use regular replacement to remove the blanks.
The final result:
张志斌张志斌张志斌张志斌张志斌张志alsdkjf;laskjd;flasj;asdjfasjd;lkafsj;lfdkjaksdjfl;ak
In addition: \s represents blank characters, \S represents non-blank characters (pay attention to upper and lower case, generally upper and lower case means the opposite meaning)
The above is the entire content of this article, I hope it will be helpful to everyone's study For help, please pay attention to the PHP Chinese website for more related content!
Related recommendations:
PHP function strip_tags/htmlspecialchars
PHP strip_tags method of retaining multiple HTML tags, strip_tags tag
The above is the detailed content of Solution to using strip_tags() in php to remove html tags and still have blank spaces. For more information, please follow other related articles on the PHP Chinese website!