Generating multiple NCBI URLs with eutils 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&amp;retmode=xml&amp;retmax=10&amp;sort=relevance&amp;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 =&gt; $GS){
    $SP = $species[$key];
    $query = "$GS AND $SP [orgn] AND alive";
    $esearch = "$eutils/esearch.fcgi?db=$db&amp;retmode=xml&amp;retmax=10&amp;sort=relevance&amp;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&amp;retmode=xml&amp;retmax=10&amp;sort=relevance&amp;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).
I don't know anything about php, but when I copy your code into here it isn't happy about the variable name $query.

This code appears to produce valid urls, but I can't make the get part work:

$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 =&gt; $GS){ 
   $SP = $species[$key];
   $SearchTerm = "$GS AND $SP [orgn] AND alive";

   $esearch = "$eutils/esearch.fcgi?db=$db&amp;retmode=xml&amp;retmax=10&amp;sort=relevance&amp;term=";

   echo $esearch.$SearchTerm;
}

http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&amp;retmode=xml&amp;retmax=10&amp;sort=relevance&amp;term=A20 AND homo sapiens [orgn] AND alivehttp://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&amp;retmode=xml&amp;retmax=10&amp;sort=relevance&amp;term=HBB AND Escherichia coli [orgn] AND alivehttp://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=gene&amp;retmode=xml&amp;retmax=10&amp;sort=relevance&amp;term=ABO AND Saccharomyces cerevisiae [orgn] AND alive