With this rule below, how do I display the user's first and last name in the database?

4

Example of the name that is in the DB: José ALberto da Silva Nogueira. I would like you to show only José Nogueira.

<?php if(!Yii::$app->user->isGuest) echo Yii::$app->session->get('nomeUsuario'); ?>
    
asked by anonymous 29.12.2015 / 14:48

1 answer

4

Follow the code below:

if(!Yii::$app->user->isGuest) {
    $nomeCompleto = Yii::$app->session->get('nomeUsuario');
    $partes = explode(" ", $nomeCompleto);
    echo $partes[0] . " " . $partes[count($partes) - 1];
}
    
29.12.2015 / 15:00