使用preg_replace()用逗号和空格替换内容

时间:2014-07-01 14:37:27

标签: preg-replace str-replace

尝试执行preg_replace()但在逗号后添加空格我用。替换换行符。

目前:

$string = preg_replace( "/\r/", ", ", $string );

但这个空间不起作用。

任何帮助?

1 个答案:

答案 0 :(得分:1)

为什么不只是str_replace()

$test = "Hello\rWorld";

$test = str_replace("\r", ", ", $test);

print $test;
// Hello, World

PHP Documentation for str_replace()