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 "      ";
}
else if (preg_match('#^OC\s+(Eukaryota)#', $item, $matches)) {
print_r($fields['tax_lin'] = $matches[1]);
echo "         
           ";
}
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;
}