php - 识别一个词并提取对应的数据
问题描述
我需要在字符串中识别 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_decode 就像@Alex Howansky 说的那样。
$data = json_decode($output);
foreach($data as $row) {
print_r($row->pmid);
}
推荐阅读
- java - 如果对象存在于 id 上,则更新数组列表
- jquery - Tablednd - 在表中使用返回的 JSON 数据
- sql-server - 分区表更新慢
- uwp - 如何解决使用 UWP GetFolderFromPathAsync 时访问被拒绝的问题
- css - 使用v-if显示子div时如何避免父元素的高度跳跃
- c# - 获得给定货币汇率之间的短路径的算法
- asp.net-mvc - 将查询字符串参数传递给 MVC 控制器中的 JsonResult 操作
- r - 对两个匹配的字符串/单词使用 ifelse 函数
- javascript - 无法将包发布到 npm
- php - 测试 laravel 社交名流重定向