The PHP formatter formats PHP code nicely. It formats any HTML found between PHP fragments reasonably considering that that the HTML is broken into arbitrary fragments by the intervening PHP elements. It does not touch code inside <script> tags.
The pair of these do what OP is looking for.
They are not online, and they are not free. OP requested "online" and "free", but got no responses in over a year.