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

时间:2012-01-03 18:13:10

标签: php regex

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

/ * update * / 我写了像

这样的代码
<?php


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

它有效。只是想知道它是否会更好。

1 个答案:

答案 0 :(得分:1)

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