Regex - Return First and Last Name

前端 未结 7 1112
一整个雨季
一整个雨季 2021-01-15 08:51

I\'m looking for the best reliable way to return the first and last name of a person given the full name, so far the best I could think of is the following

7条回答
  •  再見小時候
    2021-01-15 09:21

    Here is simple non regex way

    $name=explode(" ",$name);
    $first_name=reset($name);
    $last_name=end($name);
    $result=$first_name.' '.$last_name;
    

提交回复
热议问题