Php 识别一个单词并提取对应的数据

Php 识别一个单词并提取对应的数据,php,regex,Php,Regex,我需要在字符串中标识PMID并从中提取ID。然而,我面临的一个问题是Php 我尝试使用正则表达式来识别PMID,但没有成功 ob_start(); include('getCallbyVkey.php'); $output = ob_get_clean(); $arr1 = explode('}', $output); foreach ($arr1 as $line_){ // if (strpos($line_, 'pmid')){

我需要在字符串中标识PMID并从中提取ID。然而,我面临的一个问题是Php

我尝试使用正则表达式来识别PMID,但没有成功

   ob_start();
   include('getCallbyVkey.php');
   $output = ob_get_clean();
   $arr1 = explode('}', $output);
   foreach ($arr1 as $line_){
//        if (strpos($line_, 'pmid')){
           preg_match_all('/"pmid":#(\d+)/', $line_, $matches);
           print_r($matches);
数据如下:

[{"author":"F\u00c3\u00bchrer S","pmid":"31401120","volume":"","issue":"","year":"2019","month":"Aug","journal":"Journal of molecular biology","journalabbrev":"J. Mol. Biol.","title":"Pathogenic Mutations Associated with Legius Syndrome Modify the Spred1 Surface and Are Involved in Direct Binding to the Ras Inactivator Neurofibromin.","order":"1","source":"PubMed"}
,{"author":"Yl\u00c3\u00a4-Outinen H","pmid":"31397088","volume":"","issue":"","year":"2019","month":"Aug","journal":"Molecular genetics & genomic medicine","journalabbrev":"Mol Genet Genomic Med","title":"Intestinal tumors in neurofibromatosis 1 with special reference to fatal gastrointestinal stromal tumors (GIST).","order":"2","source":"PubMed"}
,{"author":"Ahlawat S","pmid":"31396668","volume":"","issue":"","year":"2019","month":"Aug","journal":"Skeletal radiology","journalabbrev":"Skeletal Radiol.","title":"Current status and recommendations for imaging in neurofibromatosis type 1, neurofibromatosis type 2, and schwannomatosis.","order":"3","source":"PubMed"}
,{"author":"Ahlawat S","pmid":"31395668","volume":"","issue":"","year":"2019","month":"Aug","journal":"Neurology","journalabbrev":"Neurology","title":"Imaging biomarkers for malignant peripheral nerve sheath tumors in neurofibromatosis type 1.","order":"4","source":"PubMed"}
,{"pmid":"24033266","year":"2013","title":"A systematic approach to assessing the clinical significance of genetic variants.","author":"H Duzkale","clinacc":"RCV000218671","ClinicalSignificance":"benign","source":"ClinVar"}
,{"pmid":"25741868","year":"2015","title":"Standards and guidelines for the interpretation of sequence variants: a joint consensus recommendation of the American College of Medical Genetics and Genomics and the Association for Molecular Pathology.","author":"S Richards","clinacc":"RCV000218671","ClinicalSignificance":"benign","source":"Pubmed"}

预期产出为:

31401120
31397088
31395668
24033266
25741868

json_按照@Alex Howansky的说法对其进行解码


    $data = json_decode($output);
    foreach($data as $row) {
        print_r($row->pmid);
    }


json_按照@Alex Howansky的说法对其进行解码


    $data = json_decode($output);
    foreach($data as $row) {
        print_r($row->pmid);
    }


尝试将正则表达式更改为:

preg_match_all('/"pmid":"(\d+)/', $line_, $matches);

这应该是个好办法,但正如@Alex Howansky所提到的,您可以使用
json\u decode
尝试将正则表达式更改为:

preg_match_all('/"pmid":"(\d+)/', $line_, $matches);

这应该是个窍门,但是正如@Alex Howansky提到的,你可以使用
json\u decode

这是json,使用
json\u decode()
而不是试图手动解析它。是
[{“author”:“F\u00c…
应该是字符串吗?这是json,使用
json\u decode()
而不是试图手动解析它。是
[{“author”:“F\u00c…
应该是字符串吗?