看到你,梁松远的博客

位置 » 主页 » 代码分享 » php删除网页上看不见的隐藏字符串, 如 Java\0script

php删除网页上看不见的隐藏字符串, 如 Java\0script

 /**

 * 删除网页上看不见的隐藏字符串, 如 Java\0script
 *
 * @param string
 */
function remove_invisible_characters(&$str, $url_encoded = TRUE)
{
$non_displayables = array();
 
// every control character except newline (dec 10)
// carriage return (dec 13), and horizontal tab (dec 09)
 
if ($url_encoded)
{
$non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
$non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
}
 
$non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
 
do
{
$str = preg_replace($non_displayables, '', $str, -1, $count);
}
while ($count);
}