$userName = "John Doe"; $firstName = explode(' ',trim($userName))[0]; echo "Hello ".$firstName;
if(isset($_POST['submit'])){ $fullName = $_POST['fullName']; $firstName = explode(' ',trim($fullName))[0]; echo "Hello ".$firstName. " - thank you for submitting the form!"; }In this example, the user submits a form that includes their full name. The getFirstName function is used to extract the first name of the user, which is then used to personalize the response message. Package/library: This example uses standard PHP functions, and no external package/library is required.