- var_dump: documentation ( source)
- preg_replace_callback: documentation ( source)
- preg_replace: documentation ( source)
<?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);