我正在编写一个脚本来输出从 PubMed Central API 抓取的排序信息。我的问题是我想提取第一作者和第二作者以及第一个和第二个关键字(就这个问题而言,我们可以只关注一个)。一个很好的例子是在$xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->surname
。显然,我可以得到要打印的名字。
根据我阅读其他帖子的理解,我需要一个foreach
循环来实现我想要的。但是,我不明白如何在这种情况下实现这一点。我的代码如下:
<?php
$PMCID = 3545513;
$url = 'http://www.pubmedcentral.nih.gov/oai/oai.cgi?verb=GetRecord&identifier=oai:pubmedcentral.nih.gov:'.$PMCID.'&metadataPrefix=pmc_fm';
$xml = new SimpleXMLElement(file_get_contents($url));
?>
<table>
<tr>
<td>Journal Title</td><td>Year</td><td>Issue</td><td>NOC_Country</td><td>State</td><td>City</td><td>Primary Institution</td><td>Secondary Institution</td><td>First Author</td><td>Second Author</td><td>Topic</td><td>Target Behavior 1</td><td>Target Behavior 2</td><td>Population</td><td>Paper</td><td>Status</td>
</tr>
<tr>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'journal-meta'}->{'journal-title-group'}->{'journal-title'};?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'pub-date'}->year;?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->issue;?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->surname;?>, <?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->{'given-names'};?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->surname;?>, <?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->{'given-names'};?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'title-group'}->{'article-title'};?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'kwd-group'}->kwd;?></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'kwd-group'}->kwd;?></td>
<td></td>
<td><?php echo $xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'article-categories'}->{'subj-group'}->subject;?></td>
<td></td>
</tr>
</table>
任何帮助将不胜感激!