December 21st, 2000, 03:35 PM
-
How do you take a characters off the end of a varible or specify the size of a variable to be a certain size.
December 21st, 2000, 07:24 PM
-
Hope this helps:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
# our variable string
$var = "some_string";
# give the numerical length of the variable
$length_a = (length($var);
# set the substr value to hack off
# the last character.
$length_b = (length($var) - 1);
# this strips the last character off
# off the $var
$trimdown = substr($var,0,$length_b);
Now $trimdown is the $var with the last character removed.
[/code]
Cheers,
Mickalo
------------------
Thunder Rain Internet Publishing
Providing Personal/Business
Internet Solutions that work!
http://www.thunder-rain.com
December 21st, 2000, 09:41 PM
-
Or chomp() could do the job
------------------
- Son
123finder.com - Free Domain Name Generator
ad-rotator.com - Free ad rotator system for small businesses/sites
December 21st, 2000, 09:49 PM
-
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by meeh82:
How do you take a characters off the end of a varible or specify the size of a variable to be a certain size.[/quote]
For example, you have a variable named $me that contains "iamveryspecial," and you want to trim it down to, let's say 7 characters. You would do this:
$me = substr $me, 0, 7; # $me is now "iamvery"
If you would like to remove, let's say, the last 5 characters, you would approach it like this:
$me = substr $me, 0, -5; # $me is now "iamverysp"
Hope this helps!