#is\\', \\'\\', $html);
Using DOMDocument
A more reliable and safe approach is to utilize the DOMDocument class, designed for HTML parsing:
$dom = new DOMDocument();$dom->loadHTML($html);foreach ($dom->getElementsByTagName(\\'script\\') as $item) { $item->parentNode->removeChild($item);}$html = $dom->saveHTML();
Additional Alternatives
Alternatively, consider using one of the following techniques:
Security Considerations
Remember that user input should be treated as potentially unsafe. Always sanitize and validate HTML content to prevent malicious code injection. Regular expressions should only be used on trusted content.
","image":"http://www.luping.net/uploads/20241120/1732061541673d2965a6b35.jpg","datePublished":"2024-11-20T08:45:44+08:00","dateModified":"2024-11-20T08:45:44+08:00","author":{"@type":"Person","name":"luping.net","url":"https://www.luping.net/articlelist/0_1.html"}}While using HTML Purifier, you may wish to specifically remove script tags without removing inline formatting or other elements. This can be accomplished through various methods.
Using Regular Expressions
Although not recommended for HTML parsing, a simple regular expression can achieve the task:
$html = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $html);
Using DOMDocument
A more reliable and safe approach is to utilize the DOMDocument class, designed for HTML parsing:
$dom = new DOMDocument(); $dom->loadHTML($html); foreach ($dom->getElementsByTagName('script') as $item) { $item->parentNode->removeChild($item); } $html = $dom->saveHTML();
Additional Alternatives
Alternatively, consider using one of the following techniques:
Security Considerations
Remember that user input should be treated as potentially unsafe. Always sanitize and validate HTML content to prevent malicious code injection. Regular expressions should only be used on trusted content.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3