Fonksiyon içine alınan yazıda bulunan html etiketleri temizler.
<?php function HtmlTemizle ($text) { $text = preg_replace("'<script[^>]*>.*?</script>'si", '', $text ); $text = preg_replace('/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', ' ()',$text ); $text = preg_replace( '/<!--.+?-->/', '', $text ); $text = preg_replace( '/{.+?}/', '', $text ); $text = preg_replace( '/ /', ' ', $text ); $text = preg_replace( '/&/', ' ', $text ); $text = preg_replace( '/"/', ' ', $text ); $text = strip_tags($text); $text = htmlspecialchars($text); return $text; } ?>
Örnek Kullanım
<?php echo HtmlTemizle("<!DOCTYPE html> <html> <head> <title>deneme</title> </head> <body> <p> Deneme p tagı içerisi </p> </body> </html>") ?>
Çıktı: deneme Deneme p tagı içerisi
Yorumlar