将简单的HTML Dom与JSON数据相结合我不知道

时间:2015-05-27 09:50:22

标签: php ajax dom simple-html-dom

我使用ajax post方法接收了json数据。

我从tomorrow.php收到的示例格式:

  

POSTDATA = country = America& competition = Copa + Libertado& team = Boca + Juniors,content type = application / json,charset utf-8)via tomorrow.php at my simple html dom query file。我收到多个json数据,所以不只是一个POSTDATA。

我想将所有数据转换为php变量。我怎样才能做到这一点?我如何与现有的simple_html_dom查询结合使用?

我现有的简单html dom查询(我收录了bright.php,它发送了json数据与郡,竞争和俱乐部):

 <?php
    header('Content-Type: text/html; charset=utf-8');
    ini_set("user_agent", "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17");

    include ("tomorrow.php");
    include ("mysql.php");
    include_once('simple_html_dom.php');

    ini_set('display_errors', true);
    error_reporting(E_ALL);

        $filename = "footballfixtures.html";
        $html = file_get_html($filename);

    class matches {
        var $day;
        var $kickofftime;
        var $title;

            function matches ($day, $kickofftime, $title){
                    $this->day=$day;
            $this->kickofftime=$kickofftime;
                    $this->title=$title;
                    return $this;
        }
    }

    $i=0;

    $day=$html->find('h1',0);
    $day->plaintext;
    $day=str_replace("<h1>TODAY FOOTBALL FIXTURES: ","", $day);
    $day=str_replace("</h1>","", $day);
    $matchday = str_replace(array('MONDAY ', 'TUESDAY ', 'WEDNESDAY ', 'THURSDAY ', 'FRIDAY ',  'SATURDAY ',  'SUNDAY '), '', $day);
    $matchday=str_replace(" ","-", $matchday);
    $matchday=date('Y-m-d', strtotime($matchday));

    foreach($html->find('table.fixtures') as $matches) 
    {
        foreach ($matches->find('tr[class=a1],tr[class=a2]') as $matchesTR) {

        $kickofftime=$matchesTR->find('td[matches]',0)->plaintext;
        $kodate = date('Y-m-d H:i:s', strtotime("$matchday $kickofftime +1 hour"));
        $title=$matchesTR->find('pre[class=title]',0)->plaintext;


        $i++;


        $title = ucwords(strtolower($title));

        echo $kodate;
        echo $title;


       }
    }

    // clean up memory
        $html->clear();
        unset($html);

    ?>

我想将我从footballfixtures.html(启动时间和标题)收到的数据加上我通过json数据收到的数据(通过tomorrow.php)。

我希望每一行都有这些结果:

kodate,职称,比赛,国家,球队

我希望有人可以帮助我,因为我不知道。

0 个答案:

没有答案