I use Linux server for my CakePHP application. I use PHP 5.4.30.
I need to str_replace newlines from a string.
I want to use PHP_EOL
.
But var_dump(PHP_EOL)
gives this:
string(1) " "
It is strange to get empty string for this constant. I was waiting for \n
or \r
.
This works:
$text=str_replace("\r"," ",$text);
This doesn't work:
$text=str_replace(PHP_EOL," ",$text);
(All my files are UTF8 encoded)
Solution:
str_replace(PHP_EOL..)
didn't work because I get text from a Windows server and process it in Linux server. So Linux's PHP_EOL didn't find the newlines in text. Problem solved when I str_replace
both windows and unix newline characters.