Author: Asif Rahman
Demo: Example
A standalone PHP class provides a wrapper around the PubMed API. Fully documented with working examples.
- Access PubMed through a proxy server programatically
- Limit the total number of search results
- Pagination splits search results amoung multiple pages
- Optional exact search term matching
- Cache search results as JSON formatted text files
- Load search results from cache
- Control lifetime of cache results
See the script in action at the Soterix Medical publications browser.
To get started:
include('PubMedAPI.php');
$search_term = 'search query';
$PubMedAPI = new PubMedAPI();
$results = $PubMedAPI->query($search_term);
The query()
method returns an array of search results or an empty array if no matches were found.
Interaction with the PubMed API is accomplished in two steps. Given a search term, the first query returns a list of PMIDs. The second query returns the metadata of each article. query()
takes three arguments, the first is the search term string (this can also be the PMID if already known), the second is a boolean that returns a compact result if TRUE
, and the third is an optional callback function to manipulate the results.
Returns the pmid, volume, issue, year, month, pages, issn, journal, journalabbrev, title, abstract, affiliation, authors, articleid, keywords of each article.
Refer to the class file for more documentation.
This script is free software, available under the terms of the BSD-style open source license reproduced below, or, at your option, under the GNU General Public License version 2 or a later version.
PHP PubMed API Wrapper
Copyright © 2012 Asif Rahman
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name "PHP PubMedAPI Wrapper" nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.