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??? Link to comment https://forums.phpfreaks.com/topic/27035-need-some-help-with-word-breaking/ 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] Link to comment https://forums.phpfreaks.com/topic/27035-need-some-help-with-word-breaking/#findComment-123630 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 Link to comment https://forums.phpfreaks.com/topic/27035-need-some-help-with-word-breaking/#findComment-123631 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. Link to comment https://forums.phpfreaks.com/topic/27035-need-some-help-with-word-breaking/#findComment-123632 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 Link to comment https://forums.phpfreaks.com/topic/27035-need-some-help-with-word-breaking/#findComment-123639 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.