Template:Fname
Jump to navigation
Jump to search
<?php $fullName = {{{1}}};
// Split the full name into an array of words using space as the delimiter $nameParts = explode(" ", $fullName);
// Check if there are at least two parts (first name and last name) if (count($nameParts) >= 2) {
$firstName = $nameParts[0]; $lastName = $nameParts[1]; // Assuming the last name is the second part
// Construct the desired format "lname, fname" $formattedName = $lastName . ", " . $firstName; echo $formattedName; // Output: Doe, John
} else {
echo "Invalid name format.";
} ?>