Use PHP to filter the code that may be used in html to introduce external dangerous content. Sometimes, users must submit html content to enrich the information published by users. of course, some codes that may cause messy page layout are also filtered out. Use PHP to filter the code that may be used in html to introduce external dangerous content. Sometimes, users must submit html content to enrich the information published by users. of course, some codes that may cause messy page layout are also filtered out.
The following are functions used to filter HTML code:
Function ihtmlspecialchars ($ string ){ If (is_array ($ string )){ Foreach ($ string as $ key => $ val ){ $ String [$ key] = ihtmlspecialchars ($ val ); } } Else { $ String = preg_replace ('/& (# (\ d {3, 5} | x [a-fA-F0-9] {4 }) | [a-zA-Z] [a-z0-9] {2, 5});)/',' & \ 1 ', Str_replace (array ('&', '"', '<', '>'), array ('&', '"', '<', '> '), $ string )); } Return $ string; } |