Thursday, 22 August 2013

Echoing specific element IDs' values in multidimensional array

Echoing specific element IDs' values in multidimensional array

I am programming a script to output sorted information grabbed from the
PubMed Central API. My issue is that I would like to pull the first and
second authors as well as the first an second keywords (for the purposes
of this question, we can focus on just one). A good example of this is at
$xml->GetRecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->surname.
I can, obviously, get the first name to print.
It is my understanding from reading other posts that I need a foreach loop
to achieve what I desire. I do not, however, understand how to implement
this in this context. My code is as follows:
<?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>
Any help would be greatly appreciated!

No comments:

Post a Comment