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 #174593 is a reply to message #174592] Mon, 20 June 2011 23:04 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On Mon, 20 Jun 2011 14:19:31 -0700, Co 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?

a) Count back from the end of the string to find the location of the last
space, and truncate the string to that point.

b) split the name string into an array, and add bits of the string
together with spaces until the next added bit would exceed your maximum
length.

There may be other ways.

Rgds

Denis McMahon
[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: Tue Nov 26 19:57:29 GMT 2024

Total time taken to generate the page: 0.04813 seconds