dongmou5628 2018-02-28 09:25
浏览 157
已采纳

PHP cURL字符串获取字符串某些部分之前和之后的所有内容

Im usin cURL to crabb some data from webpage. But as the data is array based, but the size changes and varies. Then i need to search for parts of string and want to get everyhting after the part til next comma.

{"id":2988001,"teatiseNr":"50000099027","mkood":74,

Now here is the string. I would only like to have everything after {"id": til the first comma. So my output would be 2988001

Why i need the search criteria is because some times there are more variables and that messes up the order. Right now im using simple

$pieces = explode(",", $page);

And then just delete the rest with

str_replace('{"id":','',$pieces[0]);

There must be more elegant way to make this work.

  • 写回答

2条回答 默认 最新

  • doudi4014 2018-02-28 09:36
    关注

    this is a json string, so you can simply do:

    $data = json_decode($string);
    
    echo $data->id;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?