<?php $string = "James said hello\n\n\n\n Test\n Test two\n\n"; echo json_encode( preg_replace("/\n{2,}/", "\n", $string) ); echo "\n---\n"; $string = "James\r\n said\n\r\n hello\r\n\r\n\r\n Test\n Test two\n\n"; echo json_encode( preg_replace("/\R{2,}/", PHP_EOL, $string) );
You have javascript disabled. You will not be able to edit any code.