Solved

How to shorten a to long name?

Posted on 1998-11-21
7
167 Views
Last Modified: 2010-03-04
It should do the following:
e.g.


old name >> thisnameistolong

names longer than 10 should be converted in >> thisnameis..


if(length($name) > 10) {

$name = ?;

}


Regards,

Bigi
0
Comment
Question by:Bigi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 4

Expert Comment

by:martinag
ID: 1206427
$name = substr($name,0,10) if length($name) > 10;

Martin
0
 
LVL 4

Expert Comment

by:martinag
ID: 1206428
I didn't see the two spots. Add using ."..":
$name = substr($name,0,10).".." if length($name) > 10;

Martin
0
 

Author Comment

by:Bigi
ID: 1206429
Thanks!

How can I grade it?

Please reply with "answer" (not comment) so I can send
you the points.

Regards,

Bigi
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
martinag earned 80 total points
ID: 1206430
$name = substr($name,0,10).".." if length($name) > 10;

Martin
0
 

Author Comment

by:Bigi
ID: 1206431
Adjusted points to 80
0
 
LVL 4

Expert Comment

by:martinag
ID: 1206432
Thanks.

Martin
0
 
LVL 84

Expert Comment

by:ozo
ID: 1206433
#or
substr($name,10)='..'
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl to convert excel to csv 3 339
Perl string replace for refred url 9 73
how to print sub line with  sed /awk /perl in bash file 11 94
Perl Versus AWK? 7 97
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question