FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » use of substring in php
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: use of substring in php [message #174595 is a reply to message #174592] Tue, 21 June 2011 00:41 Go to previous messageGo to previous message
dougatmilmacdotcom is currently offline  dougatmilmacdotcom
Messages: 24
Registered: May 2011
Karma:
Junior Member
In article <27917623-6bef-416e-8ce3-856e9dd20bd9(at)v10g2000yqn(dot)googlegroups(dot)com>, Co <vonclausowitz(at)gmail(dot)com> wrote:
> Hi All,
>
> I want to cut down the name of the user to 10 characters so it will
> fit to the picture of the user.
> At this moment I use $firstnameCut = substr($firstname, 0, 10);
> However sometimes the name is like:
>
> Johannes Paul.
> with my code it will show: Johannes P
>
> How can I change this so if the second or third name doesn't fit
> within the 10 characters
> it will not be shown at all?

What will you do if the *first* name doesn't fit within 10 characters? In
English-speaking countries, "Christopher" (11 characters) is a fairly common
given name for men. I have a Polish friend whose given name is Wlodzimierz
(also 11 characters). In some languages (e.g. Thai or Malayalam) names can be
*much* longer than that.

Perhaps this will produce what you want:

a) if the 11th character is a space, truncate at 10 characters and quit
b) if there are no spaces in the first 10 characters, truncate at 10 and quit
c) if neither a) nor b) is true, search backward from the 10th character and
truncate at the first space you find.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Compiling PHP error
Next Topic: free computer ebooks updated daily
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 12:00:24 GMT 2024

Total time taken to generate the page: 0.03967 seconds