繁体   English   中英

阅读网页html源代码并使用php将表添加到数组中

[英]reading a webpage html source code and adding table into arrays with php

我试图阅读网页的源代码并将表的信息添加到数组中

该网页是http://dsrd.uc.cl/dara/libcursos/periodo21/ua5_1.html

在表格中,我想将列“profesores”添加到数组profesores []和列“nombre asignatura”到数组curso [];

我知道我可以通过以下方式获取网页来源:

$homepage = file_get_contents('http://www.example.com/');

但我不知道如何管理字符串来创建数组。

一种方法是使用DOMDocument:

$doc = new DOMDocument();
$doc->loadHTML($homepage);
$table = $doc->getElementsByTagName("table")->item(/* Find out which one it is */)
$rows = $table->getElementByTagName("tr")
for ($i = 0; $i length; $i++)
{
    $row = $rows->item($i);
    /* Find columns and add it to your array */
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM