PHP正则表达式

PHP正则表达式,php,preg-match,file-get-contents,Php,Preg Match,File Get Contents,如何预匹配总计数 来自php中的这段代码 { "data": [ { "name": "Baptiste Chimay", "administrator": false, "id": "10153820811316460" }, "summary": { "total_count": 4956 } } 我试过了,但没有得到任何数据 $url = ('the url i want');

如何预匹配总计数 来自php中的这段代码

{
   "data": [
      {
         "name": "Baptiste Chimay",
         "administrator": false,
         "id": "10153820811316460"
      },
   "summary": {
      "total_count": 4956
   }
}
我试过了,但没有得到任何数据

$url = ('the url i want');
                $result = json_decode($url);
    $likes = preg_match("'total_count (.*?),'si", file_get_contents($url), $matches);
print_r($url);

只需避开引用:

preg_match("/total_count\"\:(.*?)/i", file_get_contents($myurl), $matches);
//               here __^
但是,你不需要逃离塞尔米科隆

preg_match("/total_count\":(.*?)/i", file_get_contents($myurl), $matches);
您还可以将双引号替换为单引号:

preg_match('/total_count":(.*?)/i', file_get_contents($myurl), $matches);
preg_match('/total_count":(\d+)/i', file_get_contents($myurl), $matches);
并将
*?
更改为
[^”]+

您还可以将双引号替换为单引号:

preg_match('/total_count":(.*?)/i', file_get_contents($myurl), $matches);
preg_match('/total_count":(\d+)/i', file_get_contents($myurl), $matches);

这是json数据,您可以使用
json\u decode
创建php数组:

$data = json_decode(file_get_contents($myurl), true);

echo $data['summary']['total_count']; //outputs 4956

看起来像(部分)json-这是该url的全部输出吗?不是全部输出请添加全部输出。Php本机支持json,因此regex不是最好的解决方案。我实际上会从
[^”]
改为
d+
@mloureiro:你说得对