PHP Replacing Pattern With Found String – String Function

 
    <html>
<head>
<title>preg_replace</title>
</head>
<body>
<?php
     $string = "<a href=\"http://www.w3mentor.com/\">w3mentor</a><br />";$pattern = '/<a[ .]*?(href *= *".*?").*?>(.*?)<\/a>/i';
     $replacement = '\2: <a \1>\1</a>';$string = preg_replace($pattern, $replacement, $string);
     print($string);
?>
</body>
</html>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.