PHP replace href using regexp

PHP Replace href values of anchor using regexp, Replace href values of html links using regular expressions, php – Regular Expression to Search+Replace href, preg_replace change link from hre, PHP replace href, regex replace href.

Replace anchor href attribute value using regular expression in php. PHP code sample given for replace href value by regexp. REGEXP helpful when you working with html parsing or working on html content changes.

PHP code for replace anchor tag href attribute value.

$oldLink = '<a href="http://vevlo" title="Title text">Vevlo.com</a>';
$newHref = 'http://www.google.com';

$pattern = "/(?<=href=(\"|'))[^\"']+(?=(\"|'))/";
$newLink = preg_replace($pattern, $newHref, $oldLink);  

echo $newLink;