Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #2267

Re: use of substring in php

From dougatmilmacdotcom@example.com (Doug Miller)
Newsgroups comp.lang.php
Subject Re: use of substring in php
Date 2011-06-21 00:41 +0000
Organization A noiseless patient Spider
Message-ID <itopc9$j4l$1@dont-email.me> (permalink)
References <27917623-6bef-416e-8ce3-856e9dd20bd9@v10g2000yqn.googlegroups.com>

Show all headers | View raw


In article <27917623-6bef-416e-8ce3-856e9dd20bd9@v10g2000yqn.googlegroups.com>, Co <vonclausowitz@gmail.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.

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

use of substring in php Co <vonclausowitz@gmail.com> - 2011-06-20 14:19 -0700
  Re: use of substring in php Denis McMahon <denis.m.f.mcmahon@gmail.com> - 2011-06-20 23:04 +0000
  Re: use of substring in php Bill B <me@privacy.net> - 2011-06-20 20:40 -0400
    Re: use of substring in php Allodoxaphobia <knock_yourself_out@example.net> - 2011-06-21 12:36 +0000
  Re: use of substring in php dougatmilmacdotcom@example.com (Doug Miller) - 2011-06-21 00:41 +0000
    Re: use of substring in php bobmct <bobm3@worthless.info> - 2011-06-20 21:16 -0400
  Re: use of substring in php Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-06-21 11:04 +0200

csiph-web