$config = ' #Start User username1 ServerName username1.someserver ServerAlias www.username1.someserver DocumentRoot /var/www/username1/ AllowOverride AuthConfig FileInfo Indexes Limit Options #End User username1'; echo preg_replace('/#Start User username1.*#End User username1/s', '', $config);