I am working on Drupal 7 Omega Subtheme, Panels Views. In one of my views I have a path field which displays the whole url and I need only the last 6 characters (6 digits, to be precise. Also, if it helps - part of the URL I want to get rid of is fixed.) Under REWRITE options there is 'Trim this field to a maximum length' but I need to trim it from the end (i.e. from the right). Do I have to use php? Do I require views_php module? Thanks.


Yes. You will have to use something like

$newstring = substr($dynamicstring, -6);

in the php code for the field.

  • Thanks Gokul. How would I use tokens (namely - [path]) in combination with that?
    – Zel
    Jul 3 '14 at 11:50
  • Could I do something like $Dynamicstring == [path]; $newstring = substr($dynamicstring, -6); print $newstring;
    – Zel
    Jul 3 '14 at 11:52
  • If you are using view_php it should be available to you as a php variable. If you want to use tokens you can use <?php token_replace('[path]'); ?>
    – Gokul N K
    Jul 3 '14 at 11:55
  • Also, is there a drupal way of doing this as sorting a view using PHP always has a considerable perfomance impact?
    – Zel
    Jul 3 '14 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.