// Load the HTML file $dom = new DOMDocument(); $dom->loadHTMLFile('file.html'); // Find the anchor tag $a_tag = $dom->getElementsByTagName('a')[0]; // Remove the target attribute $a_tag->removeAttribute('target');
// Load the XML file $dom = new DOMDocument(); $dom->loadXML($xml_string); // Find the person element $person = $dom->getElementsByTagName('person')[0]; // Remove the age attribute $person->removeAttribute('age');This method is part of the PHP DOM extension, which is built-in and does not require any external package or library.