Php 如何从字符串中获取数据

Php 如何从字符串中获取数据,php,arrays,Php,Arrays,我对API REST做了一个GET请求,得到了一些数据(base64编码) 现在我需要从结果中得到一些特定的值,但我不知道如何得到 这就是我到目前为止所拥有的 <?php //BUSCAR DOCUMENTOS $service_url = 'http://192.168.4.77/api/Core.svc/core/PaginatedSearch/P/E/KFRpcG9EVEU6MzMgQU5EIEZjaEVtaXM6WzIwMTktMDYtMjEgVE8gMjAxOS

我对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)

字符串(3340)"37753825 1号33 2284 21-06-2019 0:00:00 2 77606550-1里约热内卢塞拉诺旅游社会酒店+79800310-0dte@comapa.cl科马帕旅游酒店dte@comapa.cl314162 50160 2640020户外0终极世界语角竞技场角竞技场角竞技场521111更正V?lida Si Si Espera Acuse Recibo Si 21-06-2019 9:24:31环境3775382577606550-1\send\33\2019\06\21\T033N000000000002284S776065501R798003100D20190621.xml不确定号21-06-2019 9:30:04不确定号21-07-2019 16:55:01 37754716 1号33 2285 21-06-2019 0:00:00 2 77606550-1里约塞拉诺S.A.里约热内卢酒店+79800310-0dte@comapa.cl科马帕旅游酒店dte@comapa.cl 314162 50160 264002 0 户外0终极世界语竞技场Punta Arenas Ultima Esperanza Punta Arenas Punta Arenas 521111更正V?lida Si Si Espera Acuse Recibo Si 21-06-2019 9:47:31 Enviado 37754716 77606550-1\send\33\2019\06\21\t033n00000002285S776065501R798003100D20190621.xml定义编号21-06-2019 9:50:22定义21-07-2019 16:55:13“

任何帮助都将不胜感激。

看起来数据结构合理,即使是一团乱麻

似乎有一个键表示
,键,一个值表示
,值,然后它继续重复。使用它,我们至少可以将其分解为一个更合理的关联数组

$structured_response = [];
$keys = explode('<_DocID>', $response); //First we'll look for the keys

foreach ($keys as $key) {
  if ($key == '') continue;
  $data  = explode('<_Group>', $key); //Then we'll look for what's around on either side of the value denotation
  $key   = $data[0]; //Before the key-ending separator will be the key
  $value = $data[1]; //After the separator will be the data

  $structured_response[$key] = $value; //Now save the data to the array
}
$structured_response=[];
$keys=explode(“”,$response);//首先我们将查找键
foreach($key作为$key){
如果($key='')继续;
$data=explode(“”,$key);//然后我们将查找值表示两边的内容
$key=$data[0];//在键结束分隔符将成为键之前
$value=$data[1];//分隔符后面是数据
$structured_response[$key]=$value;//现在将数据保存到数组中
}

是谁对你做的?给你这样的数据。我建议从这个示例代码中去掉
AuthKey
。我假设这是一个私有的、非共享的值。@paskl是电子账单的APIcompany@B.Fleming谢谢,我把它删除了!有没有可能是原始数据,也就是说,不是粘贴到队列中的数据选项—是否以制表符分隔?也就是说,数据的不同部分是否可能实际上由
制表符
/
\t
字符分隔?此外,是否可能数据的另一部分—例如,
$Result
$Description
—包含有助于检索特定列的更好的数据或信息om
$Data
?这只是覆盖了值,所以最终得到了一个结果。我没有意识到每次都是相同的两个键值,让我来修改一下。否则它就像一个非常简洁的解决方案。我正在做一些事情,比如从中提取XML,你可以进行解析。但我一看到你的想法就扔掉了代码。荣誉。@zbee谢谢我的朋友,现在要打印结果,我应该在$structured_response[$key]var上做一个var_dump,print_r,echo吗?我很感激;我一直在寻找
explode()
haha的好用法。实际上,我很喜欢让它能够解析XML的想法,我想知道这看起来会是什么样子——我可以试试。
$structured_response = [];
$keys = explode('<_DocID>', $response); //First we'll look for the keys

foreach ($keys as $key) {
  if ($key == '') continue;
  $data  = explode('<_Group>', $key); //Then we'll look for what's around on either side of the value denotation
  $key   = $data[0]; //Before the key-ending separator will be the key
  $value = $data[1]; //After the separator will be the data

  $structured_response[$key] = $value; //Now save the data to the array
}