【问题标题】:How Remove Quotes, Unwanted Data From JSON String of CURL Response PHP API如何从 CURL 响应 PHP API 的 JSON 字符串中删除引号、不需要的数据
【发布时间】:2018-12-22 18:26:57
【问题描述】:

伙计们如何从卷曲响应中删除不需要的数据,如双双引号和字符串(126)我只需要 URL,我得到了这个卷曲响应:

字符串(126)"http://www.mydomainxyz.co/router/offers/74938e12xxxxxf519d57bd63252d/pre_entry?sdk=false&uid=805xxxx03&ai_id=15xx719261"

我只需要普通网址请帮助我已经尝试了很多事情但没有好的结果代码如下:

    <?php

  $url_send ="https://www.mydomainxyz.co/supply_api/surveys/offer?";


 function sendPostData($url, $post){
  $ch = curl_init($url);
  curl_setopt($ch,CURLOPT_USERAGENT,'Content-type: application/json');
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "api_token=eca8c17xxxxxxxxx486ec8a7271&user_identifier=80xxxxxx9203");

  $jsonStr = curl_exec($ch);
  curl_close($ch);

  $json = json_decode($jsonStr, true);
  var_dump($json['offer_url']);
}

echo " " . sendPostData($url_send, $str_data);

?>

【问题讨论】:

    标签: php arrays json string curl


    【解决方案1】:

    在你的函数sendPostData()你使用

    var_dump($json['offer_url']);
    

    问题出在哪里。您真的只需要返回该值,这将在最后的 echo 中打印出来。所以把var_dump()改成...

    return $json['offer_url'];
    

    【讨论】:

    • 太棒了,它工作了,谢谢先生,我不是很好的编码员,对不起,现在只清理网址
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 2013-04-17
    • 2015-11-05
    • 2017-06-04
    • 2021-11-04
    • 2021-03-23
    相关资源
    最近更新 更多