It depends on how its stored in the $name variable
i.e.
Smith, John
or
John Smith
most I am guessing that you will just have to use strtok to divide the $name string using a token character
i.e.
$name= "smith, john";
//grab first segment
$currentNamePart = strtok($name, ",");
//assign first segment
$lastName = $currentNamePart;
//grab Secon segment
$currentNamePart = strtok($name, ",");
//assign Second segment
$firstName = $currentNamePart;