PubMed API

The NCBI provides a web service interface to PubMed. For searching this is a two-step process that first performs the search then retrieves the results. Here's an example in PHP5:


if ($xml = simplexml_load_file('http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&retmax=0&usehistory=y&term=' . urlencode($argv[1]))){
  if ($xml = simplexml_load_file("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&retmode=xml&query_key={$xml->QueryKey}&WebEnv={$xml->WebEnv}&retstart=0&retmax=10")){
    $docs = $xml->DocSum;
  }
}
print_r($docs);

The query terms are passed in as a command line argument. The retstart and retmax parameters determine the offset and number of items to return. See the EUtils documentation for full information.