在这段代码中,有两个 foreach。当我单独使用它时效果很好。但是,它不能一起工作。我已经为这个问题苦苦挣扎了两天。。
$urls = nl2br($this->input->post('urls'));
$result = explode("<br />", $urls);
$n = 0;
foreach($result as $row)
{
$n++;
$Google_Play_URL = $row;
$string = file_get_contents($Google_Play_URL);
$dom = new DOMDocument();
@$dom->loadHTML($string);
$anchors = $dom->getElementsByTagName('a');
$i = 0;
foreach ($anchors as $anchor)
{
$i++;
if ($anchor->nodeValue === 'Email Developer') {
$email = str_replace('mailto:', '', $anchor->getAttribute('href'));
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo $email;
$id = $this->session->userdata(SESSION_USERID);
$country = 'US';
$type = 'android';
$query = 'SELECT idx FROM db_advertisers WHERE email = "'.$email.'"';
$result = $this->db->query($query);
if($result->num_rows() < 1)
{
$query = 'INSERT INTO db_advertisers (email, type, url, country, submit_user) VALUES ("'.$email.'", "'.$type.'", "'.$Google_Play_URL.'", "'.$country.'", "'.$id.'")';
$this->db->query($query);
}
}
}
}
}
当我发送多个值时,此代码仅保存一个数据。它应该保存多个数据。你能看出问题吗?