Web から特定のページを削除するプログラムがあります。次に、残りのページをトラバースし、削除されたページへのリンクを「リンク解除」したいと思います。私は単純なhtmldomを使用しています。私の関数は、ソース ページ ($source) とページの配列 ($skipList) を取ります。リンクを見つけたら、dom を操作して要素を $link->innertext に変換したいのですが、方法がわかりません。何か助けはありますか?
function RemoveSpecificLinks($source, $skipList) {
// $source is the html source file;
// $skipList is an array of link destinations (hrefs) that we want unlinked
$docHtml = file_get_contents($source);
$htmlObj = str_get_html($docHtml);
$links = $htmlObj->find('a');
if (isset($links)) {
foreach ($links as $link) {
if (in_array($link->href, $skipList)) {
$link->href = ''; // Should convert to simple text element
}
}
}
$docHtml = $htmlObj->save();
$htmlObj->clear();
unset($htmlObj);
return($docHtml);
}