public static function parseDisplayName($string, $data)
    {
        $response = array();

        if (isset($data->sn) && !empty($data->sn)) {
            $response['firstname'] = trim(str_replace($data->sn, "", substr($string, 0, strpos($string, " - "))));
            $response['lastname'] = $data->sn;
        } elseif (isset($data->mail) && strpos($data->mail, ".")) {
            $response['firstname'] = trim(substr($data->mail, 0, strpos($data->mail, ".")));
            $response['lastname'] = trim(substr($data->mail, strpos($data->mail, ".")+1, strpos($data->mail, "@")-strpos($data->mail, ".")-1));
        } else {
            $tempData = array();
            $tempData = trim(substr($string, 0, strpos($string, " - ")));

            if (!empty($tempData)) {

                $tempData = explode(" ", $tempData);

                if (is_array($tempData) && count($tempData)) {
                    $response['lastname'] = $tempData[0];
                    unset($tempData[0]);
                    $response['firstname'] = implode(" ", $tempData);
                }
            }
        }

        //Uppercase first letters
        $response['firstname'] = ucfirst($response['firstname']);
        $response['lastname'] = ucfirst($response['lastname']);

        return $response;
    }
public static function parseDisplayName($string, $data)
    {
        $response = array();

        if (isset($data->sn) && !empty($data->sn)) {
            $response['firstname'] = trim(str_replace($data->sn, "", substr($string, 0, strpos($string, " - "))));
            $response['lastname'] = $data->sn;
        } elseif (isset($data->mail) && strpos($data->mail, ".")) {
            $response['firstname'] = trim(substr($data->mail, 0, strpos($data->mail, ".")));
            $response['lastname'] = trim(substr($data->mail, strpos($data->mail, ".")+1, strpos($data->mail, "@")-strpos($data->mail, ".")-1));
        } else {
            $tempData = array();
            $tempData = trim(substr($string, 0, strpos($string, " - ")));

            if (!empty($tempData)) {

                $tempData = explode(" ", $tempData);

                if (is_array($tempData) && count($tempData)) {
                    $response['lastname'] = $tempData[0];
                    unset($tempData[0]);
                    $response['firstname'] = implode(" ", $tempData);
                }
            }
        }

        //Uppercase first letters
        $response['firstname'] = ucfirst($response['firstname']);
        $response['lastname'] = ucfirst($response['lastname']);

        return $response;
    }
public static function parseDisplayName ( $ string , $ data ) { $ response = array ( ) ; if ( isset ( $ data -> sn ) && ! empty ( $ data -> sn ) ) { $ response [ 'firstname' ] = trim ( str_replace ( $ data -> sn , "" , substr ( $ string , 0 , strpos ( $ string , " - " ) ) ) ) ; $ response [ 'lastname' ] = $ data -> sn ; } elseif ( isset ( $ data -> mail ) && strpos ( $ data -> mail , "." ) ) { $ response [ 'firstname' ] = trim ( substr ( $ data -> mail , 0 , strpos ( $ data -> mail , "." ) ) ) ; $ response [ 'lastname' ] = trim ( substr ( $ data -> mail , strpos ( $ data -> mail , "." ) + 1 , strpos ( $ data -> mail , "@" ) - strpos ( $ data -> mail , "." ) - 1 ) ) ; } else { $ tempData = array ( ) ; $ tempData = trim ( substr ( $ string , 0 , strpos ( $ string , " - " ) ) ) ; if ( ! empty ( $ tempData ) ) { $ tempData = explode ( " " , $ tempData ) ; if ( is_array ( $ tempData ) && count ( $ tempData ) ) { $ response [ 'lastname' ] = $ tempData [ 0 ] ; unset ( $ tempData [ 0 ] ) ; $ response [ 'firstname' ] = implode ( " " , $ tempData ) ; } } } //Uppercase first letters $ response [ 'firstname' ] = ucfirst ( $ response [ 'firstname' ] ) ; $ response [ 'lastname' ] = ucfirst ( $ response [ 'lastname' ] ) ; return $ response ; }
Parse display name to extract user firstname & lastname
@return array
Parse display name to extract user firstname & lastname