Back to Developer Roadmap

Sanitization Techniques

src/data/roadmaps/php/content/[email protected]

4.0787 B
Original Source

Sanitization Techniques

Sanitization Techniques is a vital part of PHP security basics, which ensures that the user-provided data is safe to be used within your script. It can prevent harmful data from being inserted into the database or being used in other ways that could potentially be dangerous to your application. It includes functions which can strip off unwanted characters from the data. For instance, the filter_var() function in PHP can be applied to sanitize text.

$dirty_data = "<p>We love PHP!</p><script>alert('Virus!')</script>";   
$clean_data = filter_var($dirty_data, FILTER_SANITIZE_STRING);
echo $clean_data;

Visit the following resources to learn more: