使用正则表达式将数据替换为其他数据


Replacing data with another data using regular expressions

我可以用仅使用正则表达式的新文本abc is happy to work.替换像During the day, abc is working.这样的大文本吗。这是在一些文本文件中提出的。它还说代码不能超过2行。

/*更新*/我写过类似的代码

<?php

echo preg_replace(array('/During the day,/','/is/'), array('','is happy to'), 'During the day, Damien is working');
?>

它奏效了。只是想知道是否可以更好。

我相信您正在寻找的是preg_replace()http://php.net/manual/en/function.preg-replace.php.如果你需要测试你的正则表达式,我建议你http://gskinner.com/RegExr/