We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Massaging data with Volt: trim specific characters & spaces?

Greetings! I'm sure this can be done with Phalcon fillters, but with Volt alone is it possible to trim out a specific character and all spaces from {{ foo }}?

For example, say we have the string Day: Today. Is it possible to get that in the form daytoday with Volt, stripping out the colon and all spaces?

I see we have {{ string|trim }} available but could not see a way to specify characters with it.



125.8k
Accepted
answer

You can add new function to Volt - this looks like a good case for adding preg_replace()



8.1k

Or str_replace will do if you just want to remove all spaces and colons..

Yah, str_replace() would be better if the replacement is just replacing any occurrences of certain characters. Regex is computationally expensive.