ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Looking for a way to trim a variable

June 04, 2011 5:00pm

Subscribe [3]
  • #1 / Jun 04, 2011 5:00pm

    Jason Turcotte

    102 posts

    I would like to use the assign_variable function to set a variable to equal segment_2.

    However, what I need to do is trim 1 character off the end of it.

    For example, segment_2 may be “signs”. I want to assign the variable the value “sign”.

    It doesn’t appear that you can use backspace=“1” with assign_variable.

    Suggestions on how to do what I want?

    Thanks!!

  • #2 / Jun 04, 2011 5:58pm

    Kernon

    173 posts

    Jason,

    There are probably others, but I use:

    phpstringfun

  • #3 / Jun 06, 2011 5:23am

    John Henry Donovan

    12339 posts

    Jason,

    As Kernon suggests an add-on here may work. You also might run into a template parse issue as the assign_variable is parsed so early. Let us know how you get on

  • #4 / Jun 06, 2011 8:35am

    Jason Turcotte

    102 posts

    I ended up using PHP to do it.

    <?php
        $myCat = substr("{segment_2}",0,-1)
    ?>

    The I just echo the variable where I need it. Thanks to Kernon for reminding me the PHP string functions. 😊

  • #5 / Jun 06, 2011 1:56pm

    Kevin Smith

    4784 posts

    Thanks for the assist on that one, Kernon. Got everything squared away, Jason?

    Kevin

  • #6 / Jun 06, 2011 8:38pm

    Jason Turcotte

    102 posts

    Thanks for the assist on that one, Kernon. Got everything squared away, Jason?

    Kevin

    Yeah… for this thread anyways.

    I’m going crazy with category issues.  😖

  • #7 / Jun 07, 2011 6:51am

    John Henry Donovan

    12339 posts

    Thanks Jason. If your category thread pops up in Technical support we will get to it.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases