PHP How to clear the HTML format and remove the space in the text and then intercept the text, a detailed share of the processing method (by the way PHP clears the HTML string function to do a summary):
Htmlspecialchars Turning special characters into HTML
Format syntax: String Htmlspecialchars (String string);
return value: String
Function type: Data processing
Content Description This function converts special characters to HTML string format (&....;).
The most commonly used occasion may be to deal with the message of the customer message version.
& (and) turn into &
"(double quotation marks) turn into "
< (less than) turn into <
> (greater than) turn into >
This function converts only the above special characters, and does not convert all of the ASCII conversions that are determined by the HTML.
htmlentities All characters into an HTML string
Syntax: String htmlentities (String string);
return value: String
Function type: Data processing
Content Description The function is somewhat like a htmlspecialchars () function, but the function converts all string characters to the special word set of the HTML character string. However, after the conversion to read the page source code, there will be a lot of trouble, especially the text in the original code will become unintelligible, the browser to see the normal.
Strip_tags ($STR) Remove markup syntax for HTML and PHP: String strip_tags (String str); Return value: String function type: Data processing content Description: This function can remove any HTML and PHP tag strings contained in the string. If the string of HTML and PHP tags are wrong, for example, less than the symbol, it will also return errors.
PHP to remove HTML, CSS style, JS format a lot of methods, but based on experience found that they basically have a drawback: basically all the text contained in the Space or tab, after continuous exploration, finally found an ideal to remove HTML characters and can remove space, CSS style and JS PHP functions.
PHP to clear HTML, CSS, JS format and remove whitespace php function
View Code Printing
01 |
function cutstr_html( $string , $length =0, $ellipsis = ‘…‘ ){ |
02 |
$string = strip_tags ( $string ); |
03 |
$string =preg_replace( ‘/\n/is‘ , ‘‘ , $string ); |
04 |
$string =preg_replace( ‘/ | /is‘ , ‘‘ , $string ); |
05 |
$string =preg_replace( ‘/ /is‘ , ‘‘ , $string ); |
" |
; preg_match_all ( $string $string |
07 |
if ( is_array ( $string )&&! empty ( $string [0])){ |
08 |
if ( is_numeric ( $length )&& $length ){ |
09 |
$string =join( ‘‘ , array_slice ( $string [0],0, $length )). $ellipsis ; |
11 |
$string =implode( ‘‘ , $string [0]); |
PHP removes HTML tag js and CSS Styles
View Code Printing
01 |
function clearHtml( $content ){ |
02 |
$content =preg_replace( "/<a[^>]*>/i" , "" , $content ); |
03 |
$content =preg_replace( "/<\/a>/i" , "" , $content ); |
04 |
$content =preg_replace( "/<div[^>]*>/i" , "" , $content ); |
05 |
$content =preg_replace( "/<\/div>/i" , "" , $content ); |
06 |
$content =preg_replace( "/<!--[^>]*-->/i" , "" , $content ); //注释内容 |
07 |
$content =preg_replace( "/style=.+?[‘|\"]/i" ,‘‘, $content ); //去除样式 |
08 |
$content =preg_replace( "/class=.+?[‘|\"]/i" ,‘‘, $content ); //去除样式 |
09 |
$content =preg_replace( "/id=.+?[‘|\"]/i" ,‘‘, $content ); //去除样式 |
10 |
$content =preg_replace( "/lang=.+?[‘|\"]/i" ,‘‘, $content ); //去除样式 |
11 |
$content =preg_replace( "/width=.+?[‘|\"]/i" ,‘‘, $content ); //去除样式 |
12 |
$content =preg_replace( "/height=.+?[‘|\"]/i" ,‘‘, $content ); //去除样式 |
13 |
$content =preg_replace( "/border=.+?[‘|\"]/i" ,‘‘, $content ); //去除样式 |
14 |
$content =preg_replace( "/face=.+?[‘|\"]/i" ,‘‘, $content ); //去除样式 |
15 |
$content =preg_replace( "/face=.+?[‘|\"]/" ,‘‘, $content ); //去除样式 只允许小写 正则匹配没有带 i 参数 |
How PHP clears HTML formatting and removes whitespace from text and then intercepts text