Reputation: 1237
I have this long list of courses on a html page done in tables i.e.
<tr class="navyLightgrey">
<td>3ADC7S1</td><td>SOFTWARE PROJECT MANAGEMENT (IIT Sri Lanka)</td><td align="Center">2009/0</td><td align="Center">Y</td><td align="Center">
<a id="dgModules__ctl2_lnkModule" href="http://example.com">View</a>
</td>
</tr>
<tr class="navyLightgrey">
<td>3ADC7S2</td><td>SOFTWARE ARCHITECTURE (IIT Sri Lanka)</td><td align="Center">2009/0</td><td align="Center">Y</td><td align="Center">
<a id="dgModules__ctl3_lnkModule" href="http://example.com" target="_self">View</a>
</td>
</tr>
It's done in this format. I want to get the value of the second td
where it says the course name i.e. SOFTWARE ARCHITECTURE (IIT Sri Lanka) and SOFTWARE PROJECT MANAGEMENT (IIT Sri Lanka) for each tr item. I want to do a while loop through the html page and get each value and echo it. Thanks
Upvotes: 0
Views: 383
Reputation: 21449
$html = 'your html';
$dom = new DOMDocument();
$dom->loadHTML($html); // or loadHTMLFile
$xpath = new DOMXPath($dom);
$arrNodes = $xpath->query('//tr/td[2]/text()');
foreach($arrNodes as $node)
echo $node->nodeValue . '<br />';
Upvotes: 2
Reputation: 3684
That is done with "HTML DOM Parser". You can use, for example this one.
Upvotes: 1
Reputation: 75588
Use DOMDocument::loadHTML, then search for the correct element within the DOMDocument.
Upvotes: 1