Tags
Asked 2 years ago
14 Jul 2021
Views 2140
Lesley

Lesley posted

Split text string into $first and $last name in php

how to Split text string into $first and $last name in php

chirag

chirag
answered Jul 17 '21 00:00

if the text string is like "firstname lastname" than we can use space as separator and we divide the text by space and get the first name and last name

so to divide the text by space , use explode() function in PHP

$fullname="Sachin tendulkar";
$name=explode(" ",$fullname);
echo $name[0];//give you firstname which is Sachin
echo $name[1];//will print last name which is tendulkar in our case.



Post Answer