dodgeitorelse3 Posted September 17, 2013 Share Posted September 17, 2013 Hi all, I have a html file on my server so it is a local file. I would like to get the value of every second <td> in each <tr> as I said it is a local html file and is written as <table border="1" style="font-size:90%; text-align:center; margin: 5px;"> <tr> <th>Song title</th> <th>Artist</th> <th>Decade</th> <th>Genre</th> <th>Single / Pack name</th> <th>Release date</th> <th>Family Friendly</th> <th>Additional <i>Rock Band 3</i> Features</th> </tr> <tr><td>"<a href="http://en.wikipedia.org/wiki/Fortunate_Son" title="Fortunate Son">Fortunate Son</a>"<sup id="cite_ref-cover_14-0" class="reference"><a href="#cite_note-cover-14"><span>[</span>a<span>]</span></a></sup></td> <td><a href="http://en.wikipedia.org/wiki/Creedence_Clearwater_Revival" title="Creedence Clearwater Revival">Creedence Clearwater Revival</a></td> <td>1969</td> <td>Southern Rock</td> <td><span style="display:none" class="sortkey">... !</span><span class="sorttext">Single</span></td> <td><span style="display:none" class="sortkey">2007-11-20 !</span><span class="sorttext">Nov. 20, 2007</span></td> <td style="background: #90ff90; color: black; vertical-align: middle; text-align: center;" class="table-yes">Yes</td> <td style="background:#ff9090; color:black; vertical-align: middle; text-align: center;" class="table-no">None</td> </tr> <tr><td>"<a href="http://en.wikipedia.org/wiki/Juke_Box_Hero" title="Juke Box Hero">Juke Box Hero</a>"<sup id="cite_ref-cover_14-1" class="reference"><a href="#cite_note-cover-14"><span>[</span>a<span>]</span></a></sup></td> <td><a href="http://en.wikipedia.org/wiki/Foreigner_(band)" title="Foreigner (band)">Foreigner</a></td> <td>1981</td> <td>Classic Rock</td> <td><span style="display:none" class="sortkey">... !</span><span class="sorttext">Single</span></td> <td><span style="display:none" class="sortkey">2007-11-20 !</span><span class="sorttext">Nov. 20, 2007</span></td> <td style="background: #90ff90; color: black; vertical-align: middle; text-align: center;" class="table-yes">Yes</td> <td style="background:#ff9090; color:black; vertical-align: middle; text-align: center;" class="table-no">None</td> </tr> <tr><td>"<a href="http://en.wikipedia.org/wiki/Get_It_On_(T._Rex_song)" title="Get It On (T. Rex song)">Bang a Gong</a>"<sup id="cite_ref-cover_14-2" class="reference"><a href="#cite_note-cover-14"><span>[</span>a<span>]</span></a></sup><sup id="cite_ref-scheduled_to_be_removed_august_15-0" class="reference"><a href="#cite_note-scheduled_to_be_removed_august-15"><span>[</span>b<span>]</span></a></sup></td> <td><a href="http://en.wikipedia.org/wiki/T._Rex_(band)" title="T. Rex (band)">T. Rex</a></td> <td>1971</td> <td>Glam</td> <td><span style="display:none" class="sortkey">... !</span><span class="sorttext">Single</span></td> <td><span style="display:none" class="sortkey">2007-11-20 !</span><span class="sorttext">Nov. 20, 2007</span></td> <td style="background:#ff9090; color:black; vertical-align: middle; text-align: center;" class="table-no">No</td> <td style="background:#ff9090; color:black; vertical-align: middle; text-align: center;" class="table-no">None</td> </tr> <tr><td>"<a href="http://en.wikipedia.org/wiki/My_Sharona" title="My Sharona">My Sharona</a>"<sup id="cite_ref-cover_14-3" class="reference"><a href="#cite_note-cover-14"><span>[</span>a<span>]</span></a></sup></td> <td><span style="display:none" class="sortkey">Knack !</span><span class="sorttext"><a href="http://en.wikipedia.org/wiki/The_Knack" title="The Knack">The Knack</a></span></td> <td>1979</td> <td>Pop-Rock</td> <td><span style="display:none" class="sortkey">... !</span><span class="sorttext">Single</span></td> <td><span style="display:none" class="sortkey">2007-11-20 !</span><span class="sorttext">Nov. 20, 2007</span></td> <td style="background:#ff9090; color:black; vertical-align: middle; text-align: center;" class="table-no">No</td> <td style="background: #FFB; color: black; vertical-align: middle; text-align: center;" class="partial table-partial">Pro Guitar/Bass</td> </tr> <tr><td>"<a href="http://en.wikipedia.org/wiki/Cherry_Bomb_(song)" title="Cherry Bomb (song)">Cherry Bomb</a>"<sup id="cite_ref-cover_14-4" class="reference"><a href="#cite_note-cover-14"><span>[</span>a<span>]</span></a></sup></td> <td><span style="display:none" class="sortkey">Runaways !</span><span class="sorttext"><a href="http://en.wikipedia.org/wiki/The_Runaways" title="The Runaways">The Runaways</a></span></td> <td>1976</td> <td>Punk</td> <td><span style="display:none" class="sortkey">... !</span><span class="sorttext">Single</span></td> <td><span style="display:none" class="sortkey">2007-11-20 !</span><span class="sorttext">Nov. 20, 2007</span></td> <td style="background:#ff9090; color:black; vertical-align: middle; text-align: center;" class="table-no">No</td> <td style="background:#ff9090; color:black; vertical-align: middle; text-align: center;" class="table-no">None</td> </tr> goes on for another 1100 <tr>'s ......................................... I tried <?php $url = "rb3_list.html"; $html = new simple_html_dom(); $html = file_get_html($url); foreach($html->find('table tr') as $row) { $cell = $row->find('td', 1); echo $cell; } ?> but all I get is a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/282209-get-values-of-the-second-in-every-in-local-file/ Share on other sites More sharing options...
dodgeitorelse3 Posted September 17, 2013 Author Share Posted September 17, 2013 (edited) i forgot to say that simple_html_dom.php is included at the begining of the code above and that simple_html_dom.php resides in same folder as the html file and the php file Edited September 17, 2013 by dodgeitorelse3 Quote Link to comment https://forums.phpfreaks.com/topic/282209-get-values-of-the-second-in-every-in-local-file/#findComment-1449798 Share on other sites More sharing options...
vinny42 Posted September 17, 2013 Share Posted September 17, 2013 If it's cleam HTML then it's also XML, which means you can perse it as XML and use XPATH to get the right elements. It's also very advisable to try to find a different source of data, ripping content from HTML is not only difficult, it's usually also illegal. Quote Link to comment https://forums.phpfreaks.com/topic/282209-get-values-of-the-second-in-every-in-local-file/#findComment-1449808 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.