PHP removes the non-formatted function that is pasted directly from Word _php tutorial

Source: Internet
Author: User
Tags html comment
There are two kinds of general processing methods: 1. JS is removed directly from the editor. 2. After submitting to the backstage, the invalid label is removed directly from the program. Below I will share a way to deal with PHP, the success rate may not be 100%. This procedure is also on the PHP official website to see, by the way pasted over.
Copy CodeThe code is as follows:
function clearhtml ($content, $allowtags = ") {

Mb_regex_encoding (' UTF-8 ');
Replace MS special characters first
$search = Array ('/'/U ', '/'/U ', '/'/U ', '/'/U ', '/-/u ');
$replace = Array (' \ ', ' \ ', ' ' ', ' ' ', '-');
$content = Preg_replace ($search, $replace, $content);
Make sure _all_ HTML entities is converted to the plain ASCII equivalents-it appears
In some MS headers, some HTML entities is encoded and some aren ' t
$content = Html_entity_decode ($content, ent_quotes, ' UTF-8 ');
Try to strip out all C style comments first, since these, embedded in HTML comments, seem to
Prevent Strip_tags from removing HTML comments (MS Word introduced combination)
if (Mb_stripos ($content, '/* ')!== FALSE) {
$content = Mb_eregi_replace (' #/\*.*?\*/#s ', ', $content, ' m ');
}
Introduce a space into any arithmetic expressions this could be caught by strip_tags so this they won ' t be
' <1 ' becomes ' < 1 ' (Note:somewhat application specific)
$content = preg_replace (Array ('/< ([0-9]+)/'), Array (' < $ '), $content);

$content = Strip_tags ($content, $allowtags);
Eliminate extraneous whitespace from start and end of line, or anywhere there is or more spaces, convert it to one
$content = preg_replace (Array ('/^\s\s+/', '/\s\s+$/', '/\s\s+/u '), Array (', ', '), $content);
Strip out inline CSS and simplify style tags
$search = Array (' #< (strong|b) [^>]*> (. *?) #isu ', ' #< (em|i) [^>]*> (. *?) #isu ', ' # ]*> (. *?)#isu ');
$replace = Array (' $', ' $', ' $');
$content = Preg_replace ($search, $replace, $content);

On some of "newer MS Word exports, where you get conditionals of the form ' if GTE mso 9 ', etc., it appears
That whatever was in one of the HTML comments prevents Strip_tags from eradicating the HTML comment that contains
Some MS Style definitions-this last bit gets rid of any leftover comments */
$num _matches = Preg_match_all ("/\

"Best Partner Outdoor Travel"-Make travel a habit!

Do you want to give yourself a vacation if you are getting busy? Focus on your work, do you still remember when the last exercise was? Excellent partner outdoor Travel, give you a different travel experience: to the heart of freedom, then everywhere is the scenery!

';
Echo clearhtml ($content, '

');

/*
The results obtained:

"Best Partner Outdoor Travel"-Make travel a habit!

Do you want to give yourself a vacation if you are getting busy? Focus on your work, do you still remember when the last exercise was? Excellent partner outdoor Travel, give you a different travel experience: to the heart of freedom, then everywhere is the scenery!


*/
?>

http://www.bkjia.com/PHPjc/326185.html www.bkjia.com true http://www.bkjia.com/PHPjc/326185.html techarticle There are two kinds of general processing methods: 1. JS is removed directly from the editor. 2. After submitting to the backstage, the invalid label is removed directly from the program. Below I will share a way through the PHP processing, into ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.