有人可以幫我簡化這段冗餘代碼嗎?如何簡化這個冗餘代碼?
if (isset($to) === true)
{
if (is_string($to) === true)
{
$to = explode(',', $to);
}
$to = array_filter(filter_var_array(preg_replace('~[<>]|%0[ab]|[[:cntrl:]]~i', '', $to), FILTER_VALIDATE_EMAIL));
}
if (isset($cc) === true)
{
if (is_string($cc) === true)
{
$cc = explode(',', $cc);
}
$cc = array_filter(filter_var_array(preg_replace('~[<>]|%0[ab]|[[:cntrl:]]~i', '', $cc), FILTER_VALIDATE_EMAIL));
}
if (isset($bcc) === true)
{
if (is_string($bcc) === true)
{
$bcc = explode(',', $bcc);
}
$bcc = array_filter(filter_var_array(preg_replace('~[<>]|%0[ab]|[[:cntrl:]]~i', '', $bcc), FILTER_VALIDATE_EMAIL));
}
if (isset($from) === true)
{
if (is_string($from) === true)
{
$from = explode(',', $from);
}
$from = array_filter(filter_var_array(preg_replace('~[<>]|%0[ab]|[[:cntrl:]]~i', '', $from), FILTER_VALIDATE_EMAIL));
}
我試過使用變量變量,但沒有成功(我用它們已經很長時間了)。
好問題。明智的,不像這裏的大多數人。 – 2010-05-21 13:33:11
[PHP中的變量函數和變量名稱]的副本(http://stackoverflow.com/questions/1617976/variable-functions-and-variable-names-in-php)。 – outis 2010-10-02 18:58:25