Twig / PHP - Format string using Replace or Regex

前端 未结 3 1100
忘了有多久
忘了有多久 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:07

    This works for me just fine (Craft CMS):

    {# Removes all characters other than numbers and + #}
    {{ profile.phone|replace('/[^0-9+]/', '') }}
    

提交回复
热议问题