I have trouble calculating a specific column with Dom Document and Xpath.
This is how the source file looks like:
already some other tables and then...
<table><hr><tr><td><table>
<td align="center" colspan="1"><u><b>Contracts</b></u></td>
<tr><th>pos</th><th>player</th><th>age</th><th>year 1</th><th>year 2</th><th>year 3</th><th>year 4</th><th>year 5</th><th>year 6</th></tr>
<tr><td CLASS=tdp>PG</td><td CLASS=tdp><a href="JamesHarden7.htm">James Harden </a></td><td>27</td><td>20.00</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp>PG</td><td CLASS=tdp><a href="TerryRozier1.htm">Terry Rozier </a></td><td>22</td><td>1.10</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp>SG</td><td CLASS=tdp><a href="DannyGreen6.htm">Danny Green </a></td><td>29</td><td>2.60</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp>SG</td><td CLASS=tdp><a href="MarcoBelinelli3.htm">Marco Belinelli </a></td><td>30</td><td>1.50</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp>SF</td><td CLASS=tdp><a href="LuolDeng12.htm">Luol Deng </a></td><td>31</td><td>1.75</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp>SF</td><td CLASS=tdp><a href="JeremyEvans9.htm">Jeremy Evans </a></td><td>28</td><td>7.50</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp>PF</td><td CLASS=tdp><a href="JeffWithey8.htm">Jeff Withey </a></td><td>26</td><td>6.25</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp>PF</td><td CLASS=tdp><a href="LavoyAllen11.htm">Lavoy Allen </a></td><td>27</td><td>1.50</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp> C</td><td CLASS=tdp><a href="JonasValanciunas10.htm">Jonas Valanciunas </a></td><td>24</td><td>12.75</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp> C</td><td CLASS=tdp><a href="RyanHollins4.htm">Ryan Hollins </a></td><td>31</td><td>1.50</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp>SF</td><td CLASS=tdp><a href="K.J.McDaniels2.htm">K.J. McDaniels </a></td><td>23</td><td>1.50</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp>PG</td><td CLASS=tdp><a href="BrianteWeber5.htm">Briante Weber </a></td><td>24</td><td>4.35</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td CLASS=tdp>SF</td><td CLASS=tdp><a href="NicolasBrussino13.htm">Nicolas Brussino </a></td><td>23</td><td>1.00</td><td></td><td></td><td></td><td></td><td></td></tr>
</table></td><td><table>
...
I worked with this code, similar to one I've found here, but I always get "0" as result.
$doc = new DOMDocument;
$doc->loadHTML('URL');
$xpath = new DOMXPath($doc);
// sum of cells of the sixth table (contracts), in the fourth column (year1), skipping the first row (ignore Year 1)
print $xpath->evaluate('sum(//table[6]//tr[position() > 1]/td[4])');