How can I simplify this redundant code?
        Posted  
        
            by Alix Axel
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Alix Axel
        
        
        
        Published on 2010-05-21T12:56:04Z
        Indexed on 
            2010/05/21
            13:10 UTC
        
        
        Read the original article
        Hit count: 301
        
Can someone please help me simpling this redundant piece of code?
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));
}
I tried using variable variables but without success (it's been a long time since I've used them).
© Stack Overflow or respective owner