I would like to create a URL that takes input from different arrays to generate a search. The data I would like to retrieve is from NCBI. Below you can find the code I wrote. But I can't get it to work; I am stuck. Thank you in advance.
I should have something like this as result but i got nothing. https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&retmode=xml&retmax=10&sort=relevance&term=A20%20AND%20Homo%20sapiens%20%5borgn%5d%20AND%20alive%5bprop%5d
$eutils = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils";
$db = "gene";
$gene_symbols = array("A20","HBB","ABO");
$species = array("homo sapiens", "Escherichia coli","Saccharomyces cerevisiae");
$links = array();
foreach ($gene_symbols as $key => $GS){
$SP = $species[$key];
$query = "$GS AND $SP [orgn] AND alive";
$esearch = "$eutils/esearch.fcgi?db=$db&retmode=xml&retmax=10&sort=relevance&term=";
#echo $esearch;
$links[] = get($esearch.$query);
}
foreach($links as $lk){
xml = simplexml_load_file($lk) or die("feed not loading");
}
var_dump(xml);
As output I got nothing.
But I would like to have this: https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&retmode=xml&retmax=10&sort=relevance&term=A20%20AND%20Homo%20sapiens%20%5borgn%5d%20AND%20alive%5bprop%5d And this for every gene. For some reason it put them all after each other and the foreach loop doesn't seem to work. I got no errors.
I run this code in php using visual studio code. The result should be visualised in the webbrowser (http://localhost/test.php).
Invalid db name specified: bccmtest
. Your code shows you are setting thedb
togene
, so what do you get when you run the actual code from your question? $\endgroup$