我在 PCRE 方法中有现有的代码,我想在 POSIX 中具有相同的功能。下面是我在 PCRE 中的示例代码。
<?php
$regex = "/(\d)/";
$content = "In the garden have dog,cat,23242,rabbit.";
echo preg_replace($regex,"<span style='color:green'>$1</span>",$content);
//Result:
//In the garden have dog,cat,<span style='color:green'>2</span><span style='color:green'>3</span><span style='color:green'>2</span><span style='color:green'>4</span><span style='color:green'>2</span>,rabbit.
我正在尝试在 POXIS 中做同样的事情,但无法获得相同的输出。下面是我在 POSIX 中的示例代码。
<?php
$regex = "([[:digit:]])";
$content = "In the garden have dog,cat,23242,rabbit."
echo ereg_replace($regex,"<span style='color:green'>$1</span>",$content);
//Result:
//In the garden have dog,cat,<span style='color:green'>$1</span><span style='color:green'>$1</span><span style='color:green'>$1</span><span style='color:green'>$1</span><span style='color:green'>$1</span>,rabbit.