douyannuo7733 2019-06-25 10:34
浏览 82

将数组和输出中的数据组合为JSON

I'm fetching some data from a website and output them in JSON. Retrieving the data is now successful, but unfortunately I am unable to sort the times and cars by date. Maybe someone can me help to get on the right track here.

    <li class="day">
    <span class="dayText">Maandag 1 juli</span>
    <ul>
        <li class="details" detailid="142">
            <div class="info">
                <span class="time">12:15</span>
            </div>
            <div class="car">
                <span class="car">
                    <a href="https://url.url">Opel Astra</a>
                </span>
            </div>
        </li>
        <li class="details" detailid="143">
            <div class="info">
                <span class="time">14:45 uur</span>
            </div>
            <div class="car">
                <span class="car">
                    <a href="https://url.url">Opel Ascona</a>
                </span>
            </div>
        </li>
    </ul>
</li>
<li class="day">
    <span class="dayText">Dinsdag 2 juli</span>
    <ul>
        <li class="details" detailid="144">
            <div class="info">
                <span class="time">03:15</span>
            </div>
            <div class="car">
                <span class="car">
                    <a href="https://url.url">Aston Martin Vanquish</a>
                </span>
            </div>
        </li>
        <li class="details" detailid="145">
            <div class="info">
                <span class="time">08:23 uur</span>
            </div>
            <div class="car">
                <span class="car">
                    <a href="https://url.url">Fiat Panda</a>
                </span>
            </div>
        </li>
    </ul>
</li>

Output wanted (JSON): The output should resemble this as much as it can. The hard thing is to have the two times match the date.

{
"date": "Maandag 1 juli" {
    "time": "12:15"
    "car": "Opel Astra"
    "time": "14:45"
    "car": "Opel Ascona"
}
"date": "Dinsdag 2 juli" {
    "time": "03:15"
    "car": "Aston Martin Vanquish"
    "time": "08:23"
    "car": "Fiat Panda"
}

PHP This is the PHP-code is have written this far. The output shows NULL. For some reason it can't be matched.

<?php
$html = file_get_contents('https://url.url');
preg_match_all("/\<span class\=\"dayText\"\>(.*?)\<\/span\>/", $html, $day);
preg_match_all("/\<span class\=\"time\"\>(.*?)\<\/span\>/", $html, $time);
preg_match_all("/\<span class\=\"car\"\>(.*?)\<\/span\>/", $html, $car);
$finalResult = array_combine($day[0],$time[0],$car[0]);
var_dump($finalResult);
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器