Remove html tags from string using php

remove html tags from string
PHP

Remove html tags from string using php

How to remove html tags from string using php?

We can remove html tags from string by using strip_tags() in php. The strip_tags() function strips a string from HTML, XML, and PHP tags.

Syntax : strip_tags(string,allow)

The first parameter string is mandatory and it specifies input string which we want to strip. The second parameter allow is an optional parameter, in this we can specify the tags which we can allow in that string. The tags specified in allow will not be removed.

The output will be the string without tags.

PHP :

<?php
    echo strip_tags("<p>Test <b><i>string..!</i></b></p>","<b>");
?>

In this example html tags <p>,<i> will be removed and the <b> tag will be there because we specified <b> tag as allow tag.

For more PHP solutions click here.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top