我有一个这个表,我需要在表格行中获取第二个TD的值。我可以用PHP做到这一点,怎么做?
这是我的表:
<table class = "jshop cart">
<tr class = "jshop_prod_cart odd">
<td class = "jshop_img_description_center">
<a href = "/shopping/index.php/product/view/210/3690">
<img src = "http://localhost/shopping/components/com_jshopping/files/img_products/noimage.gif" alt = "test" class = "jshop_img" />
</a>
</td>
<td style="text-align:left">
FIRST VALUE I NEED
</td>
<td>
1 ден. </td>
<td>
<input type = "text" name = "quantity[0]" value = "1" class = "inputbox" style = "width: 25px" />
</td>
<td>
1 ден. </td>
<td>
<a href = "/shopping/index.php/cart/delete?number_id=0" onclick="return confirm('Навистина сакате да го отстраните?')"><img src = "http://localhost/shopping/components/com_jshopping/images/remove.png" alt = "Отстрани" title = "Отстрани" /></a>
</td>
</tr>
<tr class = "jshop_prod_cart even">
<td class = "jshop_img_description_center">
<a href = "/shopping/index.php/product/view/169/2876">
<img src = "http://localhost/shopping/components/com_jshopping/files/img_products/thumb_3e28bb073e2ac2ca90345955ead6fc58.JPG" alt = "" class = "jshop_img" />
</a>
</td>
<td style="text-align:left">
SECOND VALUE I NEED
</td>
<td>
140 ден. </td>
<td>
<input type = "text" name = "quantity[1]" value = "1" class = "inputbox" style = "width: 25px" />
</td>
<td>
140 ден. </td>
<td>
<a href = "/shopping/index.php/cart/delete?number_id=1" onclick="return confirm('Навистина сакате да го отстраните?')"><img src = "http://localhost/shopping/components/com_jshopping/images/remove.png" alt = "Отстрани" title = "Отстрани" /></a>
</td>
</tr>
</table>
答案 0 :(得分:0)
您可以使用像Simple HTML DOM Parser这样的DOM解析器:
$ret = $html->find('td', 2);
答案 1 :(得分:0)
PHP不会用于此方案,因为它是服务器端语言。 PHP在服务器上运行,而不是在客户端上运行。除非您愿意通过Javascript将整个页面的数据发送到PHP,否则我认为没有理由使用PHP来选择这些值。我认为你应该使用jQuery来提取这些值。 jQuery有很多方法可以做这样的事情。做一个基本的谷歌搜索。
答案 2 :(得分:0)
如果在PHP处理期间有表,则可以在其上使用XPath。这样的事情:(考虑这个伪代码,没有测试就打字)
$xpath = new DOMXPath($doc);
$values= $xpath->query("/table/tr/td[2]");
foreach ($values as $value)
{
echo $value->nodeValue;
}
答案 3 :(得分:0)
只是一个想法,你可以使用jquery。为元素分配一个id,你可以有一个隐藏的输入。
在html中,类似这样:
<input type="hidden" id="test" value="<?=row['value']?>">
在jquery中,你可以获得元素值,如下所示:
<script>
$(document).ready(function(){
$('#button').click(function() {
$('#sub_cont').fadeIn('fast');
$("#content #sub_cont").load("postpage.php?id="+ $("#test").val());
});
});
</script>