我有2個字符串是這樣的:刪除2個字符串中的重複標籤?
$post_des = 'Neque porro quisquam est qui do <a href = "http://example.com/lorem_ipsum"> lorem ipsum </a> quia dolor sit amet, consectetur, adipisci velit...';
$post_detail = '<a href = "http://example.com/lorem_ipsum">lorem ipsum </a> dolor sit amet, consectetur adipiscing elit. Donec quis purus finibus, ultricies diam at, faucibus nunc. Donec ac luctus ipsum,vitae <a href = "http://example.com/vehicula"> vehicula </a> erat. ' ;
,並希望刪除所有重複AHREF標籤,就像這樣:
$post_des = 'Neque porro quisquam est qui do <a href = "http://example.com/lorem_ipsum"> lorem ipsum </a> quia dolor sit amet, consectetur, adipisci velit...';
$post_detail = 'lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis purus finibus, ultricies diam at, faucibus nunc. Donec ac luctus ipsum,vitae <a href = "http://example.com/vehicula"> vehicula </a> erat. ' ;
我試圖用DOM文檔和in_array,但還有約2百萬個標籤(ex lorem ipsum,vehicular)。有沒有更簡單的方法?
您可能需要使用類似SUBSTR與array_splice一起,但我必須去現在這麼着做出來完全一樣。 – Andrew