This code will help you to remove unnecessary invisible characters
function clean($data) {
$data = htmlspecialchars($data);
$data = stripslashes($data);
$data = trim($data);
$sanitized_data = preg_replace('/[^a-zA-Z0-9()!,._\/\-\+\*\[\]\%\$\#\&\@ \\ ]/i', '', $data);
return $sanitized_data;
}
Sample Usage
<!DOCTYPE html>
<html>
<body>
<?php
$txt = "PHP";
function clean($data) {
$data = htmlspecialchars($data);
$data = stripslashes($data);
$data = trim($data);
$sanitized_data = preg_replace('/[^a-zA-Z0-9()!,._\/\-\+\*\[\]\%\$\#\&\@ \\ ]/i', '', $data);
echo "Original Test : ". $data;
echo "<br/>";
return $sanitized_data;
}
echo "Sanitized Text". clean("I love Smart Life![s] + 2-3*/ 50% $ offer on Non Veg,._-+Chicken&Popcorná");
echo "<hr/>";
echo "Sanitized Text". clean("Non Veg,Chicken Nugggetsá,300,,10,,0.5,1 Portion - Delicious @ #5& Chicken Nugggetsá,1");
?>
</body>
</html>
0 comments:
Post a Comment