<?php
$data = <<< DATA
data
data
#comment
;comment
data ;comment
data #comment
DATA;
echo preg_replace(
'/
[;#] # find strings starting with ; or #
.* # and everything following that
$ # until it ends in a newline
/mx', // make it span multilies
'',
$data
);