HTML ファイル内に存在するすべてのタグから alt タグを削除したいと考えています。実際には、多くのタグで alt を削除していますが、少数ではありません。なぜだか理解できなかった?誰でも私を助けることができます。事前にThx。以下は、およびを削除する私のコードです。
function get_clear_data($html){
$dom = new DOMDocument();
$dom->loadHTML($html);
foreach($dom->getElementsByTagName('img') as $image)
{
$image->removeAttribute('alt');
$image->removeAttribute('xmlns');
$image->removeAttribute('title');
}
$final_data=$dom->saveHTML();
return $final_data;
}
HTML タグのサンプルは次のとおりです。
<img align="middle" alt="«math xmlns=¨http://www.w3.org/1998/Math/MathML¨»«mo»§#8712;«/mo»«/math»" class="Wirisformula" src="/ckeditor_3.6.1//plugins/ckeditor_wiris/integration/showimage.php?formula=811d8a98dc8c17603bbb0d65bece4423.png" title="Double click to edit"> R define <img align="middle" alt="«math xmlns=¨http://www.w3.org/1998/Math/MathML¨»«msup»«mi»e«/mi»«mi»z«/mi»«/msup»«mo»=«/mo»«msup»«mi»e«/mi»«mi»x«/mi»«/msup»«mo»§nbsp;«/mo»«mo»(«/mo»«mi mathvariant=¨normal¨»cos«/mi»«mo»§nbsp;«/mo»«mi»y«/mi»«mo»§nbsp;«/mo»«mo»+«/mo»«mo»§nbsp;«/mo»«mi»i«/mi»«mo»§nbsp;«/mo»«mi mathvariant=¨normal¨»sin«/mi»«mo»§nbsp;«/mo»«mi»y«/mi»«mo»§nbsp;«/mo»«mo»)«/mo»«mo»§nbsp;«/mo»«mi mathvariant=¨normal¨»sin«/mi»«mo»§nbsp;«/mo»«mi»z«/mi»«mo»§nbsp;«/mo»«mo»=«/mo»«mfrac»«mn»1«/mn»«mrow»«mn»2«/mn»«mi»i«/mi»«/mrow»«/mfrac»«mo»(«/mo»«msup»«mi»e«/mi»«mrow»«mi»i«/mi»«mi»z«/mi»«/mrow»«/msup»«mo»-«/mo»«msup»«mi»e«/mi»«mrow»«mo»-«/mo»«mi»i«/mi»«mi»z«/mi»«/mrow»«/msup»«mo»)«/mo»«mo»§nbsp;«/mo»«mo»§nbsp;«/mo»«mi»a«/mi»«mi»n«/mi»«mi»d«/mi»«mo»§nbsp;«/mo»«mi mathvariant=¨normal¨»cos«/mi»«mo»§nbsp;«/mo»«mi»z«/mi»«mo»§nbsp;«/mo»«mo»=«/mo»«mfrac»«mn»1«/mn»«mn»2«/mn»«/mfrac»«mo»(«/mo»«msup»«mi»e«/mi»«mrow»«mi»i«/mi»«mi»z«/mi»«/mrow»«/msup»«mo»+«/mo»«msup»«mi»e«/mi»«mrow»«mo»-«/mo»«mi»i«/mi»«mi»z«/mi»«/mrow»«/msup»«mo»)«/mo»«/math»" class="Wirisformula" src="/ckeditor_3.6.1//plugins/ckeditor_wiris/integration/showimage.php?formula=7044dd31440f7c753195b5b5e09ba431.png" title="Double click to edit">