Tags
Asked 3 years ago
9 Jun 2021
Views 257
jignesh

jignesh posted

how to remove html tags from string in php ?

how to remove html tags from string in php ?
kord

kord
answered Apr 26 '23 00:00

You can remove HTML tags from a string in PHP using the strip_tags function. The strip_tags function removes all HTML and PHP tags from a given string.

Here is an example of how to use strip_tags function in PHP:



$string_with_tags = "<p>This is some <strong>text</strong> with <a href='#'>HTML</a> tags.</p>";
$stripped_string = strip_tags($string_with_tags);
echo $stripped_string;

Output:



This is some text with HTML tags.

In the example above, the strip_tags function is applied to the $ string_with_tags variable, which contains the original string with HTML tags. The function returns the same string with all HTML tags removed, and the resulting string is stored in the $ stripped_string variable. Finally, the resulting string is printed to the screen using the echo statement.
Post Answer