
Removing HTML tags from data in PHP is a crucial step for sanitizing user input or displaying content safely. This process involves using the strip_tags() function to eliminate any HTML or PHP tags from a string, leaving only plain text. It’s essential for preventing potential security risks, such as cross-site scripting (XSS) attacks, and ensuring that the content is clean and displayed correctly in different contexts.
Syntax:
strip_tags(string, allowed_tags)
Parameters Values:
Return Value: It returns a string where HTML tags are removed except for the allowed tags.
echo strip_tags(
"Devsocial.net one of the popular
online learning site");
?>
OUTPUT:
Devsocial.net one of the popular online learning site
Example 2: The strip_tags() function, with the allowed_tags parameter set to
echo strip_tags( "GeeksforGeeks one of the popular online learning site"); ?>