-
- function trip_html( $html, $len ) {
- // $html should contain an HTML document.
- // This example will remove HTML tags, javascript code
- // and whitespace characters. Some common
- // HTML entities will also be converted into corresponding text.
- $search = array (“''si”, // Remove javascript
- “'<[/!]*?[^< ;>]*?>'si", // Remove HTML tags
- "'([rn])[s]+'", // Remove whitespace characters
- "'&(quot|#34);'i ", // Replace HTML entity
- "'&(amp|#38);'i",
- "'&(lt|#60);'i",
- "'&(gt|#62);'i ",
- "'&(nbsp|#160);'i",
- "'&(iexcl|#161);'i",
- "'&(cent|#162);'i",
- "' &(pound|#163);'i",
- "'&(copy|#169);'i",
- "'(d+);'e"); // Run as PHP code
- $replace = array ("",
- "",
- "\1",
- """,
- "&",
- "<",
- ">",
- " ",
- chr(161),
- chr (162),
- chr(163),
- chr(169),
- "chr(\1)");
- $text = preg_replace ($search, $replace, $html);
- $text = trim($text );
- return mb_strlen($text) >= $len ? mb_substr($text, 0, $len) : ”;
- }
- ?>
Copy code
|