<?php
$var = 'This
that
then
thar
these
them';

$var = preg_replace('/\n(?=.*?\n)/', "\n\t", $var);

echo $var;
?>