Now you listen here! He's not the messiah; he's a very naughty boy! Now go away! The multitude,Who are you? Brians mother,I'm his mother; that's who! The multitude,Behold his mother! Behold his mother! EOT; function convert($csv) { $out = []; array_map(function($ln) use(&$out) { $ln = htmlentities($ln); $out[] = count($out) == 0 ? ''.implode('',explode(',',$ln))."\n" : ''.implode('',explode(',',$ln))."\n"; }, explode("\n",$csv)); return ''.implode('',$out).'
'; } echo convert($csv);