Question and answer is powered by AnsPress.io
I want to get the first name from a full name, which name value stored in a PHP variable.
If my variable like that:
<?php $myname = 'Amit Biswas'; ?>
Here I want to display only Amit. How can I display first word of my name?
<?php echo "Amit"; ?>
Display the first name from a full name in a PHP.
Follow this example code and apply it in your PHP code.
<?php // Your code here! $myname = 'Amit Biswas'; $array = explode(' ',trim($myname)); echo $array[0]; ?>
Output: Amit