preg_replace正则表达式替换特定标记中的链接

preg_replace正则表达式替换特定标记中的链接,replace,preg-replace,href,Replace,Preg Replace,Href,我需要一个帮助,我只想替换特定div类中指向我的链接的href链接 <div id="slider1" class="owl-carousel owl-theme"> <div class="item"> <div class="imagens"> <a href="http://oldsite.com/the-fate-of-the-furious"><img src="https://image.oldste.or

我需要一个帮助,我只想替换特定div类中指向我的链接的href链接

<div id="slider1" class="owl-carousel owl-theme">
  <div class="item">
    <div class="imagens">
      <a href="http://oldsite.com/the-fate-of-the-furious"><img src="https://image.oldste.org" alt="The Fate of the Furious" width="100%" height="100%" /></a>
      <span class="imdb">
        <b class="icon-star"></b> N/A
      </span>
    </div>
    <span class="ttps">The Fate of the Furious</span>
    <span class="ytps">2017</span>
  </div>
</div>

不适用
暴怒者的命运
2017
这里我想换成

我想这些链接像

<a href="http://newsite.com/?id=the-fate-of-the-furious">

请帮助我使用preg_替换正则表达式

谢谢这可能对你有帮助

     $content = get_the_content();
     $pattern = "/(?<=href=(\"|'))[^\"']+(?=(\"|'))/";
     $newurl = get_permalink();
     $content = preg_replace($pattern,$newurl,$content);

     echo $content;
$content=获取内容();

$pattern=“/(?lookbehind太贵了,请使用
\K
启动完整字符串匹配并避免捕获组

代码():

$in='1!'
不适用
暴怒者的命运
2017
';
echo preg_更换('/
不适用
暴怒者的命运
2017
$in='<div id="slider1" class="owl-carousel owl-theme">
<div class="item">
<div class="imagens">
<a href="http://oldsite.com/the-fate-of-the-furious"><img src="https://image.oldste.org" alt="The Fate of the Furious" width="100%" height="100%" /></a>
<span class="imdb"><b class="icon-star"></b> N/A</span>
</div>
<span class="ttps">The Fate of the Furious</span>
<span class="ytps">2017</span>
</div>';

echo preg_replace('/<a href="\K[^"]+\//','http://newsite.com/?id=',$in);
<div id="slider1" class="owl-carousel owl-theme">
<div class="item">
<div class="imagens">
<a href="http://newsite.com/?id=the-fate-of-the-furious"><img src="https://image.oldste.org" alt="The Fate of the Furious" width="100%" height="100%" /></a>
<span class="imdb"><b class="icon-star"></b> N/A</span>
</div>
<span class="ttps">The Fate of the Furious</span>
<span class="ytps">2017</span>
</div>