php - replacing new line characters with coma from given text -


here have tried replace newline char comma. checked previous threads , acted accordingly still no solution.

$letters = '#\s+#'; $rep   = ','; $output  = str_replace($letters, $rep, trim($text)); echo $output; 

link demo : http://ideone.com/dofosc

str_replace() string replace , not regex replace. preg_replace() should used if want regex-based replace. however, replace each new line comma using:

$output = str_replace(array("\n", "\r\n"), ",", $text); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -