我有两个函数做 preg_match 来检查 emp# 和电子邮件是否有效。如果一个或两个无效,它将被打印到 error.log 但我想以一种方式组织它嗯....让我看看我是否知道如何尽可能简单地举例。
假设如果 emp# 无效,则错误日志将显示
date()
emp#
如果电子邮件无效,则会显示错误日志
date()
email
如果两者都无效,则错误日志将显示
date()
emp#
email
问题是当这两种情况都发生时,我不希望它打印日期两次或多个 emp# 或电子邮件无效日期不会重复只会打印
date()
emp#
emp#
emp$
希望我的解释是有道理的......我现在拥有的是
if(((isEmailAddressWellFormed($column[3]) == false)) && ((isStudentNumberWellFormed($column[0]) == false)))
{
$filehandle = fopen("./courses/path/error.log","a+") or die ("File can not be opened");
fwrite($filehandle, date("F t, Y (h:i:s a)") . PHP_EOL);
fwrite($filehandle, "Improper email address from " . $_GET["filename"] . " :" . PHP_EOL);
fwrite($filehandle, "$column[2] $column[1] $column[3]\n" . PHP_EOL);
fwrite($filehandle, "Improper student numbers from " . $_GET["filename"] . " :" . PHP_EOL);
fwrite($filehandle, "$column[2] $column[1] $column[0]\n" . PHP_EOL);
fclose($filehandle);
}
else
{
if(isEmailAddressWellFormed($column[3]) == false)
{
$filehandle = fopen("./courses/path/error.log","a+") or die ("File can not be opened");
fwrite($filehandle, date("F t, Y (h:i:s a)") . PHP_EOL);
fwrite($filehandle, "Improper email address from " . $_GET["filename"] . " :" . PHP_EOL);
fwrite($filehandle, "$column[2] $column[1] $column[3]\n" . PHP_EOL);
fclose($filehandle);
}
if(isStudentNumberWellFormed($column[0]) == false)
{
$filehandle = fopen("./courses/path/error.log","a+") or die ("File can not be opened");
fwrite($filehandle, date("F t, Y (h:i:s a)") . PHP_EOL);
fwrite($filehandle, "Improper student numbers from " . $_GET["filename"] . " :" . PHP_EOL);
fwrite($filehandle, "$column[2] $column[1] $column[0]\n" . PHP_EOL);
fclose($filehandle);
}
}
但我知道它没有得到我想要的……有什么简单的方法可以实现吗?