protected function readName($name)
    {
        $name = trim($name);
        $firstName = NULL;
        $lastName = NULL;
        preg_match('/([^,]+),([^,]+)/', $name, $matches);
        if (count($matches) > 0) {
            $lastName = trim($matches[1]);
            $firstName = isset($matches[2]) ? trim($matches[2]) : '';
        } else {
            preg_match_all('/[^\s]+/', $name, $matches);
            if (isset($matches[0])) {
                $matches = $matches[0];
            }
            if (count($matches) > 1) {
                $lastName = array_pop($matches);
                $firstName = implode(' ', $matches);
            }
            if (count($matches) == 1) {
                $firstName = $matches[0];
            }
        }
        return array('firstname' => $firstName, 'lastname' => $lastName);
    }
protected function readName($name)
    {
        $name = trim($name);
        $firstName = NULL;
        $lastName = NULL;
        preg_match('/([^,]+),([^,]+)/', $name, $matches);
        if (count($matches) > 0) {
            $lastName = trim($matches[1]);
            $firstName = isset($matches[2]) ? trim($matches[2]) : '';
        } else {
            preg_match_all('/[^\s]+/', $name, $matches);
            if (isset($matches[0])) {
                $matches = $matches[0];
            }
            if (count($matches) > 1) {
                $lastName = array_pop($matches);
                $firstName = implode(' ', $matches);
            }
            if (count($matches) == 1) {
                $firstName = $matches[0];
            }
        }
        return array('firstname' => $firstName, 'lastname' => $lastName);
    }
protected function readName ( $ name ) { $ name = trim ( $ name ) ; $ firstName = NULL ; $ lastName = NULL ; preg_match ( '/([^,]+),([^,]+)/' , $ name , $ matches ) ; if ( count ( $ matches ) > 0 ) { $ lastName = trim ( $ matches [ 1 ] ) ; $ firstName = isset ( $ matches [ 2 ] ) ? trim ( $ matches [ 2 ] ) : '' ; } else { preg_match_all ( '/[^\s]+/' , $ name , $ matches ) ; if ( isset ( $ matches [ 0 ] ) ) { $ matches = $ matches [ 0 ] ; } if ( count ( $ matches ) > 1 ) { $ lastName = array_pop ( $ matches ) ; $ firstName = implode ( ' ' , $ matches ) ; } if ( count ( $ matches ) == 1 ) { $ firstName = $ matches [ 0 ] ; } } return array ( 'firstname' => $ firstName , 'lastname' => $ lastName ) ; }
Try to get a first and last name from a name string

@param string $p_name

@return array Array with key 'firstname' and 'lastname'
Try to get a first and last name from a name string