3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = 'id=1 username=foobar comment=This is a sample comment'; $result = preg_replace_callback( '/\b(comment=)(.+)$/ms', function (array $matches) { return $matches[0] . preg_replace("/[\r\n]+/", " ", $matches[1]); }, $data ); var_dump($result);

preferences:
38.87 ms | 402 KiB | 5 Q