用属性替换 <a> 之间的标题

Replacing caption between <a> with attributes

我正在尝试 preg_replace link 标题,如下所示。找不到替换会考虑标签属性的示例,而不仅仅是干净的标签

基本上,这个

  <a href="/some/address" class="active">Database Title</a> 

需要变成这样

  <a href="/some/address" class="active">My Own Title</a> 

感谢帮助

您可以使用正则表达式和反向引用

$html = '<a href="/some/address" class="active">Database Title</a>;
$html = preg_replace("/(<.+>).+(<.+>)/", "My Own Title", $html);

echo $html;

http://www.php.net/manual/en/regexp.reference.back-references.php