This built-in functionality you are requesting will be difficult to get. They are many work arounds
1.) you can use external library like like htmlpurifier
http://htmlpurifier.org/
2.) use of strip_tags()
you can use strip_tags()
to allow certain tags tob passed while stripping out other html dangerous tags
Eg to allow only <h1> and <b>
while stripping out other tags you can do this
$text_strip = '<h1>Am nancy.</h1><div>hhhh</div> <b>Mooree</b> <a href="">remove me</a>';
// Allow only <h1> and <a>
echo strip_tags($text_strip , '<h1><b>');
see list of data filtering method available
data filtering: https://www.php.net/manual/en/book.filter.php
3.) use of FILTER_SANITIZE_STRING()
You can also use FILTER_SANITIZE_STRING()
to filter out dangerous text inputs
echo filter_var ($text_text, FILTER_SANITIZE_STRING);
see list of all available sanitization methods
sanitization: https://www.php.net/manual/en/filter.filters.sanitize.php
An Updates
one more thing. You can still be vulnerable to sql injection attack even if you are using pdo. This because the pdo performs sanitization by emulation of deprecated mysql_real_escape_string() function. you will need to force pdo to disable emulation and use direct prepared statements. i will update my answer
To resolve this issue see code below for database connections. charset is set to utf8
$db = new PDO ('mysql:host=localhost;dbname=mydb;charset=utf8',
'root', // username
'root123' // password
);
//Disable Emulates pdo and thus forces PDO to use real prepared statement.
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
with this above you are 100% safe against all sorts of sql injection attack. give me a shout on the comment if you appreciate this