Solved

How to shorten a to long name?

Posted on 1998-11-21
7
160 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
  • 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now