Size Kullandığım 2 tane fonksiyonu yazacağım
Birincisi: Php manuel'de verilen bir fonksiyon tüm html kodlarını temizler.
function htmltemizle($gel)
{
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip out html tags
"'([\r\n])[\s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace html entities
"'&(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"); // evaluate as php
$replace = array ("",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$text = preg_replace ($search, $replace, $gel);
return $text;
}
//Kullanımı
echo htmltemizle("<h1>Adminclup</h1>");
İkinci Fonksiyon ise html kodlarının çalışmasını engeller " ' < > escape eder
function temizle($gel){
$deger=trim(strip_tags(htmlspecialchars($gel,ENT_QUOTES)));
$deger=str_replace("&","&",$deger);
return $deger;
}
// Kullanımı
echo temizle("<script>alert('BST')</script>");
Alıntı.