What PHP function can be used to remove HTML tags from a string?
When working with user-generated content or data from external sources, it's important to sanitize input to prevent potential security risks such as XSS attacks. One common task is to remove HTML tags from a string to ensure that only plain text is displayed. In PHP, you can achieve this using the `strip_tags()` function, which removes all HTML and PHP tags from a string.
// Input string with HTML tags
$input = "<p>This is a <strong>sample</strong> text with <a href='#'>HTML</a> tags.";
// Remove HTML tags from the input string
$cleanedString = strip_tags($input);
echo $cleanedString;
Related Questions
- In the context of PHP and MySQL, what best practices should be followed when constructing and executing database queries to avoid syntax errors?
- What are the potential benefits of creating thumbnails for images in terms of website performance?
- How can PHP mail scripts be optimized to correctly handle special characters in form submissions?