如何从字符串中获取数据

我向 API REST 发出了 GET 请求,并获得了一些数据(base64 编码)。


现在我需要从结果中获得一些特定的值,但我不知道如何。


这是我到目前为止


<?php


    //BUSCAR DOCUMENTOS

    $service_url = 'http://192.168.4.77/api/Core.svc/core/PaginatedSearch/P/E/KFRpcG9EVEU6MzMgQU5EIEZjaEVtaXM6WzIwMTktMDYtMjEgVE8gMjAxOS0wNy0zMF0p/0/10';     

    $ch = curl_init($service_url);


    curl_setopt($ch, CURLOPT_URL, $service_url);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(

      'AuthKey: top-secret',

      'Content-Type: application/json',

      'Accept: application/json',

    ));

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);


    $response = curl_exec($ch);

    $err = curl_error($ch);


    if ($err) {


    echo "cURL Error #:" . $err;


    } else {


        $datos = json_decode($response,true);


        foreach ($datos as $k => $v) {

            $Result = $datos['Result'];

            $Description = $datos['Description'];

            $SearchTime = $datos['SearchTime'];

            $TotalDocuments = $datos['TotalDocuments'];

            $Data = $datos['Data'];

        }

        $test = base64_decode($Data);

        var_dump($test);

    }


    curl_close($ch);

?>

这就是我得到的,需要获取值(例如:33 2284 21-06-2019 0:00:00)

任何帮助将非常感激。


富国沪深
浏览 140回答 1
1回答

冉冉说

看起来数据是相当结构化的,即使是一团糟。好像有一个键表示<_DocID>,键,值表示<_Group>,值,然后继续重复。使用它,我们至少可以将其分解为一个更合理的关联数组。$structured_response = [];$keys = explode('<_DocID>', $response); //First we'll look for the keysforeach ($keys as $key) {&nbsp; if ($key == '') continue;&nbsp; $data&nbsp; = explode('<_Group>', $key); //Then we'll look for what's around on either side of the value denotation&nbsp; $key&nbsp; &nbsp;= $data[0]; //Before the key-ending separator will be the key&nbsp; $value = $data[1]; //After the separator will be the data&nbsp; $structured_response[$key] = $value; //Now save the data to the array}
打开App,查看更多内容
随时随地看视频慕课网APP