Answers for "php remove all attributes from anchor and p tags"

PHP
1

Remove all attributes from HTML tags in PHP

$text = '<div class="test"><p onmousemove="javascript:alert(1);">Clean <a href="#">text</a></p></div>';

$cleanText = preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/si",'<$1$2>', $text);
Posted by: Guest on January-14-2021
0

php remove anchor tag from string

$text = "<a href='http://www.google.com/'>Google1</a><br>" .
        "<a>Google2</a><br>" .
        "<afaketag href='http://www.google.com'>Google2</afaketag><br>" .
        "<afaketag>Google4</afaketag><br>" . 
        "<a href='http://www.google.com'><img src='someimage.jpg'></a>";
echo preg_replace("/<\/?a( [^>]*)?>/i", "", $text);
Posted by: Guest on June-24-2020

Browse Popular Code Answers by Language