生成的代码应该一次生成多个URL

时间:2018-04-26 13:44:01

标签: php url information-extraction

我想创建一个从不同数组获取输入以生成搜索的URL。我想要检索的数据来自NCBI。您可以在下面找到我编写的代码。但我无法让它发挥作用;我被卡住了。提前谢谢。

我应该有这样的结果,但我一无所获。 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

<blink>

</blink>

$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);

1 个答案:

答案 0 :(得分:0)

$eutils = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi";

   $databank = "gene";
   $gene_symbols = array("A20","HBB","ABO");

   $species = array("homo sapiens", "Escherichia coli","Saccharomyces cerevisiae");


    foreach($gene_symbols as $value => $GS){
        $Species = $species[$value];


        $esearch = "$GS%AND%alive[prop]%AND+$Species[orgn]";
        $esearch_test = "$eutils?db=$databank&retmode=xml&retmax=10&sort=relevance&term=$esearch";
        $result = file_get_contents($esearch_test);
        echo "Query: " . $esearch_test. "<br \>\n";
        echo "Result: " . $result . "<br \>\n";

        $xml = simplexml_load_string($result);
        echo "Count:<br \>\n";
        echo $xml->Count;
        $C =  $xml->Count;
        echo $C;
    }