i programming script output sorted information grabbed pubmed central api. issue pull first , second authors first second keywords (for purposes of question, can focus on one). example of @ $xml->getrecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'}->contrib->name->surname
. can, obviously, first name print.
it understanding reading other posts need foreach
loop achieve desire. not, however, understand how implement in context. code 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 appreciated!
ended with:
<table> <tr> <td><strong>journal title</strong></td><td><strong>year</strong></td><td><strong>issue</strong></td><td><strong>first author</strong></td><td><strong>second author</strong></td><td><strong>topic</strong></td><td><strong>target behavior 1</strong></td><td><strong>target behavior 2</strong></td><td><strong>paper</strong></td> </tr> <?php $pmcid = $_request['pmcid']; $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)); ?> <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> <?php $n=0; foreach($xml->getrecord->record->metadata->article->front->{'article-meta'}->{'contrib-group'} $author){ echo "<td>" . $author->contrib->name->surname . ", "; echo $author->contrib->name->{'given-names'} . "</td>"; $n++; if($n==2) break; } unset($n); unset($author); ?> <td><?php echo $xml->getrecord->record->metadata->article->front->{'article-meta'}->{'title-group'}->{'article-title'};?></td> <?php $i=0; foreach($xml->getrecord->record->metadata->article->front->{'article-meta'}->{'kwd-group'}->kwd $keyword){ echo "<td>" . $keyword . "</td>"; $i++; if($i==2) break; } unset($i); unset($keyword); ?> <td><?php echo $xml->getrecord->record->metadata->article->front->{'article-meta'}->{'article-categories'}->{'subj-group'}->subject;?></td> </tr> </table>