【发布时间】:2016-05-31 16:29:58
【问题描述】:
在我的数据库中,我存储电子邮件地址。在 foreach 循环中,如何跳过所有具有 @sample.com.ru 的电子邮件地址?
$sql = "SELECT * FROM myMovieCustomers";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll();
foreach ($result as $row) {
//skip if $row['email'] contains @sample.com.ru{
//do someting with these
//}
}
【问题讨论】:
-
strpos()+continue; -
您可以将其添加到查询的 where 子句中,例如 ..
where email like '%@sample.com.ru' -
哦错过了..
email not like '%@sample.com.ru'会工作 -
@Becky 使用
and、email NOT LIKE '%@sample1.com.ru' and email '%@sample2.com.ru'。或者您可以使用正则表达式并允许任何数字跟随sample。类似email not regexp 'sample[0-9]+\.com.ru' -
@SgtAJ
%是 wildcard,@是地址的一部分