This article mainly introduces PHP using Strip_tags () to remove HTML tags still have a blank solution, involving PHP regular replacement of the relevant operating skills, the need for friends can refer to. We hope to help you.
Specific as follows:
$subject = Strip_tags ($newsRs [' content ']);//Remove HTML tag $pattern = '/\s/';//Remove Blank $content = preg_replace ($pattern, ', $ subject); $seodata [' articledescription '] = mb_substr ($content, 0, 80);//intercept 80 characters
Note: Strip_tags () in the first step; just replace the HTML tag with a space
Like what:
<p> Hello </p><p> <br/></p><p> alsdkjf;laskjd;flasj;</p>< p> asdjfasjd;lkafsj;lfdkj</p><p> aksdjfl;ak</p>
Strip_tags () after processing becomes
Hello, empty line ... ALSDKJF;LASKJD;FLASJ; Empty line ... asdjfasjd;lkafsj;lfdkj empty line ... Aksdjfl;ak
This may not be what we want, and then we'll just remove the blanks with a regular replacement.
Final Result:
Hello, Alsdkjf;laskjd;flasj;asdjfasjd;lkafsj;lfdkjaksdjfl;ak.
In addition: \s denotes whitespace characters, \s denotes non-whitespace characters (note case, general case indicates the opposite meaning)
Related recommendations:
A detailed description of the regular expression capturing group and the non-capturing group of PHP
Basic and simple examples of PHP regular expressions
Summary of common functions in PHP