Advertisement
Guest User

Untitled

a guest
Feb 9th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2. libxml_use_internal_errors(true);           // hide the parsing errors
  3. $dom = new DOMDocument;                 // init new DOMDocument
  4. if($_GET){
  5.     $dom->loadHtmlFile($_GET['open']);
  6. }else{
  7.     $dom->loadHtmlFile('http://www.stackoverflow.com');
  8. }
  9. $dom->loadHtmlFile('http://www.stackoverflow.com'); // load HTML into it
  10. $xpath = new DOMXPath($dom);                // create a new XPath
  11. $nodes = $xpath->query('//a[@href]');       // Find all A elements with a href attribute
  12. foreach($nodes as $node) {               // Iterate over found elements
  13.     $node->setAttribute('href', 'index.php?open=http://www.stackoverflow.com'.$node->getAttribute('href'));     // Change href attribute
  14. }
  15. echo $dom->saveXml();                       // output cleaned HTML
  16. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement