Hi,
If i have a variable like
$name = "Joe Blogs";
how can I trim it so it just says "Joe". I need these to work for all length not just 3 characters!
Thanks,
Larru
First word in string
Moderator: General Moderators
here ya go....
this will also work if they have more than two names (say a middle name as well)... it will trim it down up to the first space.
Code: Select all
$name = ereg_replace("\ .*$","",$name);just thought about it.... you might use this instead, so that you could retrieve their last name also if you so choose later...
only problem you might run into is if their last name is something like St. James.... it would break that apart. for this, you would need to know if they were specifying a middle name or not.
Code: Select all
$name = 'John Doe';
$nameArray = explode(" ",$name);
//first name
echo $nameArrayї0];
//second name
echo $nameArrayї1];
//etc, etc