I want to grab the last name or second word of this variable
$name = 'Sandra Bullok';
$first_token = strtok($name, ' ');
echo $first_token;
Will output "Sandra"
How can I output "Bullok"
I want to grab the last name or second word of this variable
$name = 'Sandra Bullok';
$first_token = strtok($name, ' ');
echo $first_token;
Will output "Sandra"
How can I output "Bullok"
$name = 'Sandra Bullok';
$parts = explode(' ', $name);
echo $parts[0]; // 'Sandra'
echo $parts[1]; // 'Bullok'
http://php.net/manual/en/function.explode.php
If You want to do this with strtok():
$name = 'Sandra Bullok';
$first_token = strtok($name, ' ');
$second_token = strtok(' ');
echo $first_token; // 'Sandra'
echo $second_token; // 'Bullok'