Twig / PHP - Format string using Replace or Regex

前端 未结 3 1131
忘了有多久
忘了有多久 2021-01-18 04:30

How can I format a string in Twig as follows:

For example: img = 05myphoto-Car.jpg

I need to remove the numeric prefix and -

3条回答
  •  渐次进展
    2021-01-18 05:05

    If you are willing to do it in the template, though it would be better as a controller/service, you can enable the preg_replace filter and strip numbers with something like preg_replace('/\d+/','') and use the capitalize filter in addition.

提交回复
热议问题