How can I make the following PHP code better, more efficient, shorter, elegant, etc? While it already works, I am still learning PHP and want to improve upon my current code:
<?php
$query = 'psoriasis';
$eSearchQueryParameters = array(
'db' => 'pubmed',
'term' => $query,
'retmode' => 'xml',
'retstart' => '0',
'retmax' => '500',
'usehistory' => 'y',
);
$eSearchQueryResults = simplexml_load_file('http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?' . http_build_query($eSearchQueryParameters));
$eFetchQueryParameters = array(
'db' => 'pubmed',
'retmax' => '500',
'query_key' => (string) $eSearchQueryResults->QueryKey,
'WebEnv' => (string) $eSearchQueryResults->WebEnv,
);
$eFetchURL = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?' . http_build_query($eFetchQueryParameters);
$matches = array();
preg_match_all('/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/', file_get_contents($eFetchURL), $matches);
foreach ($matches[0] as $key => $value) {
echo $value . "<br />";
}
?>