Using regex to remove link but keep anchor text

Sometimes we need to remove anchors from html while displaying html content. You can easily remove links or anchors from a html content using PHP preg_replace with regex. Here is the complete code to remove anchors tags from a string.


<?php
$str = 'PHPZAG PHP <a href="https://www.phpzag.com/" title="PHP">TUTORIALS</a> AND ARTICLES.';
echo preg_replace('#<a.*?>([^>]*)</a>#i', '$1', $str);
?>

You may like these posts