首页 > 解决方案 > 识别一个词并提取对应的数据

问题描述

我需要在字符串中识别 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

标签: phpregex

解决方案


json_decode 就像@Alex Howansky 说的那样。


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


推荐阅读