Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7597743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:13:56+00:00 2026-05-30T22:13:56+00:00

this is an edited code in which mr. Paulo Rodrigues, php curl is used

  • 0

this is an edited code in which mr. Paulo Rodrigues, php curl is used to get the entries or data in the specified webpage. it will save in the file.txt. Open the file then gets the data of each entry then loop in order for the all data required in the entries is inserted.

$ch = curl_init("http://www.uniprot.org/uniprot/?query=(annotation%3a(type%3asignal+confidence%3aexperimental))+AND+reviewed%3ayes&sort=score&limit=10&format=txt");
$fp = fopen("file.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);


while (!feof($fp))
{

$array = array();
$index = -1;

foreach ($fp as $line) {
if (preg_match('#^ID#', $line)) {
    $index++;
}

$array[$index][] = $line;
}

foreach ($array as $block) {
$fields = array();

foreach ($block as $item) {
    if (preg_match('#^ID\s+(.*?)\s#', $item, $matches)) {
        print_r($fields['prot_name'] = $matches[1]);
        echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
    } 
   else if (preg_match('#^OC\s+(Eukaryota)#', $item, $matches)) {
       print_r($fields['tax_lin'] = $matches[1]);
         echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
             &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
    } 
    else if (preg_match('#LOCATION:\sMembrane;\s(.*?)\s#', $item, $matches)) {
        print_r($fields['sub_loc'] = $matches[1]); 

    } 

    }

    echo "<br />";

    if (!empty($fields)) {
    $f = implode(', ', array_keys($fields));
    $v = "'" . implode("', '", $fields) . "'";

    $sql = "INSERT INTO swissprot ($f) VALUES($v)";
    mysql_query($sql) or die(mysql_error());
    }


   }
 }

curl_close($ch);
fclose($fp);

the problem is that there is a warning that displays: “Warning: Invalid argument supplied for foreach() in this line. what might be the problem?

foreach ($fp as $line) {
if (preg_match('#^ID#', $line)) {
    $index++;
}

$array[$index][] = $line;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:13:57+00:00Added an answer on May 30, 2026 at 10:13 pm

    You could try this:

    $webpagedata = file('http://www.uniprot.org/uniprot/?query=annotation%3a%28type%3asignal+confidence%3aexperimental%29+reviewed%3ayes&sort=score&limit=10&format=txt');
    
    $array = array();
    $index = -1;
    
    foreach ($webpagedata as $line) {
        if (preg_match('#^ID#', $line)) {
            $index++;
        }
    
        $array[$index][] = $line;
    }
    
    foreach ($array as $block) {
        $fields = array();
    
        foreach ($block as $item) {
            if (preg_match('#^ID\s+(.*?)\s#', $item, $matches)) {
                $fields['prot_name'] = $matches[1];
            } else if (preg_match('#^OC\s+(Eukaryota)#', $item, $matches)) {
                $fields['tax_lin'] = $matches[1];
            } else if (preg_match('#LOCATION:\sMembrane;\s(Single-pass)#', $item, $matches)) {
                $fields['sub_loc'] = $matches[1];
            }
        }
    
        if (!empty($fields)) {
            $f = implode(', ', array_keys($fields));
            $v = "'" . implode("', '", $fields) . "'";
    
            $sql = "INSERT INTO spdb ($f) VALUES($v)";
            mysql_query($sql) or die(mysql_error());
        }
    }
    

    Update:

    $ch = curl_init("http://www.uniprot.org/uniprot/?query=(annotation%3a(type%3asignal+confidence%3aexperimental))+AND+reviewed%3ayes&sort=score&limit=10&format=txt");
    $fp = fopen("file.txt", "w");
    
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    
    $file = file("file.txt");
    $array = array();
    $index = -1;
    
    foreach ($file as $line) {
        if (preg_match('#^ID#', $line)) {
            $index++;
        }
    
        $array[$index][] = $line;
    }
    
    foreach ($array as $block) {
        $fields = array();
    
        foreach ($block as $item) {
            if (preg_match('#^ID\s+(.*?)\s#', $item, $matches)) {
                print_r($fields['prot_name'] = $matches[1]);
                echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
            } else if (preg_match('#^OC\s+(Eukaryota)#', $item, $matches)) {
                print_r($fields['tax_lin'] = $matches[1]);
                echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                 &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
            } else if (preg_match('#LOCATION:\sMembrane;\s(.*?)\s#', $item, $matches)) {
                print_r($fields['sub_loc'] = $matches[1]);
            }
        }
    
        echo "<br />";
    
        if (!empty($fields)) {
            $f = implode(', ', array_keys($fields));
            $v = "'" . implode("', '", $fields) . "'";
    
            $sql = "INSERT INTO swissprot ($f) VALUES($v)";
            mysql_query($sql) or die(mysql_error());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a sample (edited slightly, but you get the idea) of my XML
Update: Edited code example to use AutoA for the workaround (which was the original
Update : I edited the code, but the problem persists... Hi everyone, this is
This is the edited code: I have a two dimensional stack, like #define push(s,ele)
I have edited this from my real code, so that it is a little
Recently I was introduced to this OCaml code which in Haskell can be written
I have this code which uses Entity Framework 4.1 to access database entities: public
I edited this question after i found a solution... i need to understand why
I've edited this quite a bit and bolded my question at this point. I
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.