Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- libxml_use_internal_errors(true); // hide the parsing errors
- $dom = new DOMDocument; // init new DOMDocument
- if($_GET){
- $dom->loadHtmlFile($_GET['open']);
- }else{
- $dom->loadHtmlFile('http://www.stackoverflow.com');
- }
- $dom->loadHtmlFile('http://www.stackoverflow.com'); // load HTML into it
- $xpath = new DOMXPath($dom); // create a new XPath
- $nodes = $xpath->query('//a[@href]'); // Find all A elements with a href attribute
- foreach($nodes as $node) { // Iterate over found elements
- $node->setAttribute('href', 'index.php?open=http://www.stackoverflow.com'.$node->getAttribute('href')); // Change href attribute
- }
- echo $dom->saveXml(); // output cleaned HTML
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement