Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



47.7k
Accepted
answer

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



5.2k

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.