oauzor Posted October 18, 2012 Share Posted October 18, 2012 Hello. This is my first post, and i hope i post this topic in the right area. So, i have a script which gets content from another site using $dom and i want to manipulate the exported links. I have in the script the line " $td->getElementsByTagName('a')->item(0)->setAttribute('href', 'http://google.com'); " which edit the links from col 2, and i want to make the same with the links from col 10. And in col 10 i have some problems showing the results just like on the website. Please help. Thank you ! <?php $content = file_get_contents("http://www.soccerway.com/national/germany/bundesliga/20122013/regular-season/"); $content = '<?xml encoding="UTF-8">' . $content; libxml_use_internal_errors(true); $dom = new DomDocument(); $dom->loadHTML($content); libxml_clear_errors(); $xpath = new DomXPath($dom); $tabele = $xpath->query('//table[contains(concat(" ", normalize-space(@class), " "), "leaguetable")]'); $tabel = $tabele->item(0); $trs = $tabele->item(0)->getElementsByTagName('tr'); print '<table>'; foreach($trs as $rowIndex => $tr){ $tds = $tr->getElementsByTagName('td'); if($rowIndex > 18) continue; print '<tr>'; foreach($tds as $colIndex => $td){ if($colIndex == 2) $td->getElementsByTagName('a')->item(0)->setAttribute('href', 'http://google.com'); if($colIndex > 11) continue; // salveaza HTML printf('<td> %s </td>', $dom->saveXML($td)); } print '</tr>'; } print '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/269639-manipulate-links-from-dom/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.