How can HTML tags be removed from a string in PHP?
When working with strings that contain HTML tags in PHP, you may need to remove these tags to get plain text. One way to achieve this is by using the strip_tags() function in PHP. This function removes all HTML and PHP tags from a string, leaving only the plain text content.
<?php
$string_with_tags = "<p>This is a <strong>sample</strong> text with HTML tags.</p>";
$plain_text = strip_tags($string_with_tags);
echo $plain_text;
?>
Related Questions
- In what scenarios would it be more beneficial to store data in a database rather than in an array when working with PHP?
- What are some common pitfalls when using cookies for user login in PHP and how can they be avoided?
- How can PHP be used to retrieve data from a database based on specific conditions?