- array_map: documentation ( source)
- strtr: documentation ( source)
- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$str = "\n\n\nABC\n\nDEF\nGHI\n\n\nJKL";
preg_match_all('~\n+|.+\n?~', $str, $matches);
print_r(array_map(function($i) {return strtr($i, "\n", "#");},$matches[0]));