Don’t output indent before PHP open tag

I am trying to style my PHP script like a templating language, but the problem is, that PHP outputs the indentation before <?php tags like this:

<ul>
    <? foreach ($arr as $val) { ?>
        <li><?= $val ?></li>
    <? } ?>
</ul>

This works, but outputs

<ul>
            <li>a</li>
            <li>b</li>
    </ul>

and that is terrible.

Is there a way to not output the indentation before PHP tags?


Secondly, the <li> tag is indented twice, but I want to remove one indentation level.

Is that possible?