CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Truncating Variable Values

 



abockover
Deleted

Jan 22, 2001, 12:07 PM

Post #1 of 2 (607 views)
Truncating Variable Values Can't Post

How can I truncate a variable value? Say I have the variable $url

the value to $url = "http://bobs_house.somelamewebpagehostingsite.com/~bob/joe/cat/jon/21541c.html";

I only want the first 25 characters of $url, after the 25th character, add "..." and remove characters 26 and up

Thanks,

Aaron



sleuth
Enthusiast / Moderator

Jan 22, 2001, 12:31 PM

Post #2 of 2 (605 views)
Re: Truncating Variable Values [In reply to] Can't Post

 
You want to use the substr(); function,

First you should check to see if there are more than 25 characters though, you can use length(); for that.

if (length($variable) > 25){
$variable = substr($variable, 0, 25);
$variable .= " ....";
}

Explanations on Using Substr

Tony


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives