#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Riverside, CA
    Posts
    63
    Rep Power
    14
    How do you take a characters off the end of a varible or specify the size of a variable to be a certain size.
  2. #2
  3. Ole` Timer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    N.W. Iowa
    Posts
    472
    Rep Power
    14
    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
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    73
    Rep Power
    14
    Or chomp() could do the job

    ------------------
    - Son
    123finder.com - Free Domain Name Generator
    ad-rotator.com - Free ad rotator system for small businesses/sites
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    0
    Rep Power
    0
    <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!


IMN logo majestic logo threadwatch logo seochat tools logo