We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36926
    • 701 Posts
    Hi,

    Is there an input/output filter out there that will strip the file extension from a path. So if the path inputed is:

    assets/video/2011/video.ogg

    It would output
    assets/video/2011/image

    I need it to work for multiple extensions, well say multiple I mean ogg,ogv,mp4,flv.

    I also want to do something similar for images. But instead of strip the extension i to pretend the url with a director. For example

    assets/images/event/image.jpg
    Would get prepended with THUMB
    assets/images/event/THUMB/image.jpg

    Any suggestions?

    Thanks

    B
      • 22303 MODX Staff
      • 10,725 Posts
      Create a snippet called stripExts:

      <?php
      $exts = !empty($options) ? explode(',', $options) : array('ogg', 'ogv', 'mp4', 'flv');
      $extPos = strrpos($input, '.');
      if ($extPos !== false && in_array(substr($input, $extPos + 1), $exts)) {
          $input = substr($input, 0, $extPos);
      }
      return $input;
      


      Use it as your filter:
      [[*imageTV:stripExts]]
        • 36926
        • 701 Posts
        Quote from: opengeek at Sep 16, 2011, 07:22 PM
        Create a snippet called stripExts:

        <?php
        $exts = !empty($options) ? explode(',', $options) : array('ogg', 'ogv', 'mp4', 'flv');
        $extPos = strrpos($input, '.');
        if ($extPos !== false && in_array(substr($input, $extPos + 1), $exts)) {
            $input = substr($input, 0, $extPos);
        }
        return $input;
        


        Use it as your filter:
        [[*imageTV:stripExts]]

        Awesome, thanks opengeek. Works a treat. That's saved selecting 120 odd via modx smiley

        Now for the prepend the file name with a directory tongue.

        Thanks again.


        B