What is the fastest way to convert html table to php array?

Are there any built-in functions in the latest php versions specifically designed to help with this task?

+3
source share
6 answers

Use a DOM parser, such as SimpleXML , to break the HTML code into nodes and go through the nodes to build an array.

For broken / invalid HTML, SimpleHTMLDOM is softer (but not inline).

+7
source

String , HTML- , , . , XML/HTML. http://php.net/manual/en/book.dom.php

+1

DOM parser YQL. , . - YQL , .

, HTML ,

http://www.w3schools.com/html/html_tables.asp

$yql = 'http://tinyurl.com/yql-table-grab';
$yql = json_decode(file_get_contents($yql));
print_r( $yql->query->results );

URL-, . $yql YQL API, :

select * from html 
    where xpath="//table[@class='example']" 
    and url="http://www.w3schools.com/html/html_tables.asp"

YQL JSON XML. JSON , stdClass ( ). , .

YQL, , .

+1

explode, cols rows .

.: php explode

-2

Source: https://habr.com/ru/post/1761245/


All Articles