I'm trying to the last character from a smarty variable.
I knwo that I can delete the last character using substr
or also replace a character with replace
.
But I want to delete the last character only if it's ending with /
For example my string is /homepage/
, I would like to become /homepage
But If I have /homepage
it should be /homepage
EDIT :
Should also work for the string /homepage/?
-> /homepage?
You can use the Smarty regex_replace and match to \
if it's the last character with \/$
and replace it with empty string.
In the same way you can use the regex_replace
to replace /?
ending with ?
{$variable|regex_replace:"/\/$/":""|regex_replace:"/\/\?$/":"?"}