Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save khaledMohammed000/37fc49029c492d71ce05a8d9a8bb5bd0 to your computer and use it in GitHub Desktop.

Select an option

Save khaledMohammed000/37fc49029c492d71ce05a8d9a8bb5bd0 to your computer and use it in GitHub Desktop.
DOM traversal in PHP backend
// removing attribute href and width from divs
// for html code go here for testing : http://pastebin.com/ZBwEJsQ8
$dom = new DOMDocument;
$dom->loadHTML($content);
$divs = $dom->getElementsByTagName('div');
foreach ($divs as $div) {
$div->removeAttribute('href');
$div->removeAttribute('width');
}
$content = $dom->saveHTML();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment