richrock Posted May 14, 2008 Share Posted May 14, 2008 Can I create initials of users based on their firstname and lastname? I have the variables $fname and $lname, which get me the full names (example, Bob Smith), how can I strip this to B.S? Thanks Rich Link to comment https://forums.phpfreaks.com/topic/105608-create-initials-from-names/ Share on other sites More sharing options...
The Little Guy Posted May 14, 2008 Share Posted May 14, 2008 http://phpsnips.com/snippet.php?id=8 Link to comment https://forums.phpfreaks.com/topic/105608-create-initials-from-names/#findComment-541034 Share on other sites More sharing options...
benphp Posted May 14, 2008 Share Posted May 14, 2008 <?php $fname = strtoupper("Bob"); $lname = strtoupper("Marley"); print $fname{0}; print $lname{0}; ?> Link to comment https://forums.phpfreaks.com/topic/105608-create-initials-from-names/#findComment-541040 Share on other sites More sharing options...
jcombs_31 Posted May 14, 2008 Share Posted May 14, 2008 Why not just use substr? $initials = substr($firstname, 0, 1) . substr($lastname, 0, 1); Link to comment https://forums.phpfreaks.com/topic/105608-create-initials-from-names/#findComment-541043 Share on other sites More sharing options...
trq Posted May 14, 2008 Share Posted May 14, 2008 Thats should be.... <?php $fname = strtoupper("Bob"); $lname = strtoupper("Marley"); print $fname[0]; print $lname[0]; ?> {} is soon to become depricated if it isn't already. Link to comment https://forums.phpfreaks.com/topic/105608-create-initials-from-names/#findComment-541044 Share on other sites More sharing options...
trq Posted May 14, 2008 Share Posted May 14, 2008 Why not just use substr? Why use the overhead of a function call when theres no need for it? Link to comment https://forums.phpfreaks.com/topic/105608-create-initials-from-names/#findComment-541045 Share on other sites More sharing options...
benphp Posted May 14, 2008 Share Posted May 14, 2008 Thats should be.... <?php $fname = strtoupper("Bob"); $lname = strtoupper("Marley"); print $fname[0]; print $lname[0]; ?> {} is soon to become depricated if it isn't already. Ah - you're right! Link to comment https://forums.phpfreaks.com/topic/105608-create-initials-from-names/#findComment-541046 Share on other sites More sharing options...
jcombs_31 Posted May 14, 2008 Share Posted May 14, 2008 Why not just use substr? Why use the overhead of a function call when theres no need for it? I seriously doubt it will make any difference in performance. Link to comment https://forums.phpfreaks.com/topic/105608-create-initials-from-names/#findComment-541047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.