用preg_replace替换字符

时间:2019-03-02 23:46:22

标签: php regex preg-replace

使用PHP,我需要对此进行更改

^0123456789...$

对此

0123456789xxx

  1. 一开始就提取可选的^
  2. 在字符串末尾提取可选的$
  3. 将所有.替换为x

只有一个急诊室有可能吗?

1 个答案:

答案 0 :(得分:3)

最简单的方法是使用str_replace,不需要正则表达式:

$(this)

输出:

$string = '^0123456789...$';
echo str_replace(array('.', '^', '$'), array('x', '', ''), $string);
相关问题