PHP Replace Tag Content Without Getting Rid Of Any Attributes – String Function

 
    <?php
     $string = "<a href=\"http://www.w3mentor.com/\">w3mentor.com</a><br />" ;$pattern = '/<a(.*?)>.*?<\/a>/i';
     $replacement = '<a\1>Click!</a>';$string = preg_replace($pattern, $replacement, $string);
     print($string);
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.