Get data only from html table used preg_match_all in php

前端 未结 2 1464
暖寄归人
暖寄归人 2021-01-03 16:07

I have a html table like this :

string...
2条回答
  •  盖世英雄少女心
    2021-01-03 16:18

    PHP has a native extension to parse HTML and XML with DOM:

    $dom = new DOMDocument;
    $dom->loadHTML( $htmlContent );
    $rows = array();
    foreach( $dom->getElementsByTagName( 'tr' ) as $tr ) {
        $cells = array();
        foreach( $tr->getElementsByTagName( 'td' ) as $td ) {
            $cells[] = $td->nodeValue;
        }
        $rows[] = $cells;
    }
    

    Adjust to your liking. Search StackOverflow or have a look at the PHP Manual or go through some of my answers to learn more about it's usage.

提交回复
热议问题