MYSQL - txt文件中的电子邮件列表,从表中删除行

时间:2014-02-21 10:30:06

标签: php mysql sql email

这与List of emails, delete rows out of a table有关,我使用Marc的解决方案删除用txt文件写的电子邮件列表,这是

$addresses = file('emails.txt');
foreach($addresses as $address) {
    $safe_address = mysql_real_escape_string($address);
    $sql = "DELETE FROM customer WHERE (email = '$safe_address');";
    $result = mysql_query($sql) or die(mysql_error());
}

我有txt文件,其中每封电子邮件都写在一行上。但是,当我应用上述解决方案时,它只删除在该txt文件的最后一行写的一封电子邮件。

我在这里做

$addresses = file('emails.txt');
foreach($addresses as $address) {
    $safe_address = mysql_real_escape_string($address);
    echo $safe_address;
}

它给出了

jojojo@hkkjkjk.com\r\npopopo@ghghghg.com\r\ngygygy@asdfsfa.com\r\ngygyfy@asdfsfa.com\r\ngggygy@asdfsfa.com\r\ngygygy@aswfsfa.com

我尝试使用explode函数来获取\ r \的红色,因此匹配记录并删除所有记录,但没有运气。

请有人提出建议以达到目标。感谢

1 个答案:

答案 0 :(得分:0)

试一试

 $sql = "DELETE FROM customer WHERE (email = '$safe_address');";

替换为

$sql = "DELETE FROM customer WHERE email = '$safe_address' ";