How can I parse JSON into a html table using PHP?

前端 未结 5 1338
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 05:44

I have to get a table in my website. And have to get the data for this table from \"http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373\" I\'ve trie

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 06:05

    If you want recursive way:

    public static function jsonToDebug($jsonText = '')
    {
        $arr = json_decode($jsonText, true);
        $html = "";
        if ($arr && is_array($arr)) {
            $html .= self::_arrayToHtmlTableRecursive($arr);
        }
        return $html;
    }
    
    private static function _arrayToHtmlTableRecursive($arr) {
        $str = "";
        foreach ($arr as $key => $val) {
            $str .= "";
            $str .= "";
            $str .= "";
        }
        $str .= "
    $key"; if (is_array($val)) { if (!empty($val)) { $str .= self::_arrayToHtmlTableRecursive($val); } } else { $str .= "$val"; } $str .= "
    "; return $str; }

    Then call echo YourClass::jsonToDebug($jsonText);

    My test on http://sandbox.onlinephpfunctions.com/

提交回复
热议问题