Remove all special characters from string using php

Remove all special characters from string using php

Easiest away to Remove all special characters from a string using PHP. only allowed items are given in the function  string_sanitize. 

 

<?php

  $string = "Th*()is 999 is <<>> a ~!@# _ .'sample' st#$%ring. <script>alert('xss')</script> phplime.envato@gmail.com";

echo string_sanitize($string);


   function string_sanitize($data) {
    $result = preg_replace("/[^.a-zA-Z0-9@_-]+/", " ", html_entity_decode($data, ENT_QUOTES));
    return $result;
}

output: Th is 999 is a @ _ . sample st ring. script alert xss script phplime.envato@gmail.com

?>

dini sohbet Texture R57 shell indir Türk instagram takipçi satın al