Reputation: 2257
Here I have tried to replace newline char with comma. I checked previous threads and acted accordingly but still no solution.
$letters = '#\s+#';
$rep = ',';
$output = str_replace($letters, $rep, trim($text));
echo $output;
Link to demo : http://ideone.com/DoFOSc
Upvotes: 2
Views: 2266
Reputation: 664
str_replace()
is for string replace and not for regex replace. preg_replace()
should be used if you want to do a regex-based replace. However, you could replace each new line with a comma using:
$output = str_replace(array("\n", "\r\n"), ",", $text);
Upvotes: 3