How to replace different newline styles in PHP the smartest way?
$string = preg_replace(‘~\R~u’, “\r\n”, $string); If you don’t want to replace all Unicode newlines but only CRLF style ones, use: $string = preg_replace(‘~(*BSR_ANYCRLF)\R~’, “\r\n”, $string); \R matches these newlines, u is a modifier to treat the input string as UTF-8. From the PCRE docs: What \R matches By default, the sequence \R in a pattern … Read more