Chris Val Kef Posted November 12, 2006 Share Posted November 12, 2006 i need some help. i've got surnames and names and all i want to do is to showing them like this: Jack Brown => Brown J.i need help to cut the name to the first letter.anybody knows??? Quote Link to comment Share on other sites More sharing options...
trq Posted November 12, 2006 Share Posted November 12, 2006 [code]<?php $name = "Jack Brown"; $split_name = explode(" ",$name); $finished_name = $split_name[1].' '.substr($split_name[0],0,1); echo $finished_name;?>[/code] Quote Link to comment Share on other sites More sharing options...
Destruction Posted November 12, 2006 Share Posted November 12, 2006 I can give you an example though you'll have to tailor it to how you want it...[code]<?php$firstName = "Jack";$lastName = "Brown";echo $lastName.$firstName{0};?>[/code]I can't recall if it's 0 or 1 but I believe it starts at 0. The curly braces allow you to select one letter from a string by position within the string.HTHDest Quote Link to comment Share on other sites More sharing options...
Chris Val Kef Posted November 12, 2006 Author Share Posted November 12, 2006 thanx for the replies guys!the code is still the same if i got only the name?Jack => J. Quote Link to comment Share on other sites More sharing options...
Destruction Posted November 12, 2006 Share Posted November 12, 2006 If you user firstname and lastname as seperate variables then only need to use $firstName{0} for example to get the J from Jack. You can do the same with fullname as $fullName{0} which would give J from Jack Brown etc.HTHDest Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.