0
我有一個文本,我想加載爲DOMDocument並替換特定的標記。我如何解析HTML並使用DOMDocument替換特定標記
<a href="https://www.google.co.in/dsfethtrw">link1</a>
There's only one thing people of the Internet love more than an absolutely epic
<a href="https://www.google.co.in/dsfethtrfersgest">link2</a>
mistake on live television
<a href="https://www.google.co.in/ewferagre">link3</a>
我想刪除標籤和輸出應該是:
**link1**
There's only one thing people of the Internet love more than an absolutely epic
**link2**
mistake on live television
**link3**
代碼:
$dom = new DOMDocument;
$dom->loadHTML($entity->body[$field_lang][0]['value']);
foreach ($dom->getElementsByTagName('a') as $node) {
$node->removeAttribute('href');
}
$entity->body[$field_lang][0]['value'] = $dom->saveHTML();
它給我的輸出,如:
<a>link1</a> etc...
我怎麼做我擺脫標籤並僅輸出文本Ex。 link1