【问题标题】:I want to use the regex_replace only for the first character (phone number)我只想将 regex_replace 用于第一个字符(电话号码)
【发布时间】:2021-04-12 11:24:48
【问题描述】:

我只想将 regex_replaceregexp_extract 用于第一个字符(电话号码)。

例如:

89265558855 应替换 +79265558855

仅在 +7 上的前 8 个时替换

如果我使用 {$phone|regex_replace:"/8/":"+7"} 我有例如:

89265558855 替换后我有 +7926555+7+755

替换所有 8 个数字

【问题讨论】:

    标签: php smarty regexp-replace


    【解决方案1】:

    使用start of string anchor ^ 只匹配第一个字符,如下所示:

    {$phone|regex_replace:"/^8/":"+7"}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      • 2023-01-11
      • 2021-08-05
      • 1970-01-01
      • 2017-07-04
      • 2021-05-15
      • 1970-01-01
      相关资源
      最近更新 更多