我有一个替换加载的 html 上所有出现的代码,我应该如何修改它以仅替换从加载的 html 末尾开始的第一个出现?
$body = preg_replace('#<div>https://site.com/(.*?)<br />#', '<a href="site.com/$1" target="_blank">https://site.com/$1</a><br />', $body);
我加载的html:(被压缩,这没有任何断线)
<div class="clearfix spoiler"><div>https://site.com/?k=tZ1gXCyS!fywvS1E9rmnUJyjEWOkH0zHZ<br />https://site.com/#!BJchGYSB!Av27mwaKMv7zVNu9uL0fg3uUDfBoym2Lk9NeyZJp_1I<br />https://site.com/#!MdM3lDga!HHlk9SvherA-LYNAfDd9SBEwKUp3dn9oELCPVHf2mYc<br />https://site.com/#!EQ8CwZoA!QJVJMgn2cj-cmIX51Hn2OH8ySPYWw5Xy-e9tX53emDY<br />https://site.com/#!sRESXSSa!ZFuNpzMzTpF9DRohX4WNTDyo4pAkwuX0Gkh-vToQ5ec<br />https://site.com/#!NUtVmQbb!eT0qf05YySrq-hXHhj53lmTi1bcWsprB50NsZqh5MLg<br />https://site.com/#!IcdymLia!eoeI0xz-BAoVRnbL_1W2DQMUmBYtXQaaVS7-G69fY5w<br />https://site.com/#!QFVnFAKD!RhXtx3pPFrrpxw3kKmkw2ScEBgR1pD_byIvpWHHQ6ok<br />https://site.com/#!1VtDRI5J!ZUNHtxKTnnrF29z0AKLULSbsgLZ0-F_45TpmEhwijz8</div></div>
我需要替换最后一个<br />https://site.com/(.*?)</div>
(链接总是改变)白衣<div>https://site.com/$1</div>
(只有最后一场比赛或从最后开始的第一场比赛)
所以输出应该是这样的:
<div class="clearfix spoiler"><div>https://site.com/?k=tZ1gXCyS!fywvS1E9rmnUJyjEWOkH0zHZ<br />https://site.com/#!BJchGYSB!Av27mwaKMv7zVNu9uL0fg3uUDfBoym2Lk9NeyZJp_1I<br />https://site.com/#!MdM3lDga!HHlk9SvherA-LYNAfDd9SBEwKUp3dn9oELCPVHf2mYc<br />https://site.com/#!EQ8CwZoA!QJVJMgn2cj-cmIX51Hn2OH8ySPYWw5Xy-e9tX53emDY<br />https://site.com/#!sRESXSSa!ZFuNpzMzTpF9DRohX4WNTDyo4pAkwuX0Gkh-vToQ5ec<br />https://site.com/#!NUtVmQbb!eT0qf05YySrq-hXHhj53lmTi1bcWsprB50NsZqh5MLg<br />https://site.com/#!IcdymLia!eoeI0xz-BAoVRnbL_1W2DQMUmBYtXQaaVS7-G69fY5w<br />https://site.com/#!QFVnFAKD!RhXtx3pPFrrpxw3kKmkw2ScEBgR1pD_byIvpWHHQ6ok<div>https://site.com/#!1VtDRI5J!ZUNHtxKTnnrF29z0AKLULSbsgLZ0-F_45TpmEhwijz8</div></div>