我想用PHP检索表单元格的内容到另一个文件。使用这段代码,我检索行的所有单元格的内容。 如何检索特定的单元格?(第二个,例如…) Thanks.Nicolas . $url = 'folder/myPage.php';
$content = file_get_contents($url);
$first_step = explode('<tr id="foo">' , $content );
$second_step = explode('</tr>' , $first_step[1] );
echo $second_step[0];
$url = 'folder/myPage.php';
$content = file_get_contents($url);
//Ugly Code !...doesn't work !
$first_step = explode('<tr id="foo"><td[1]' , $content );
$second_step = explode('</td></tr>' , $first_step[1] );
echo $second_step[0];
我找到解决方案了!!第二次与</td>
而非</tr>
发生爆炸:
$url = 'folder/myPage.php';
$content = file_get_contents($url);
$first_step = explode('<tr id="' . $ref . '">' , $content );
$second_step = explode('</td>' , $first_step[1] );
echo $second_step[1]; // show the content of the second cell
echo $second_step[5]; // show the content of the sixth cell
// etc...
// "$ref" is a loop with foreach in a list of elements
我不想使用库来做这件事(像Simple_Html_Dom: 1800行代码,只是为了观察一个文件!!)太重了。)
对于这个解决方案,它是工作得很有魅力!我很高兴…:-)[解决了]。尼古拉。
你需要通过<td>
当然<td>
是一个'表单元格' - <tr>
是整个行