In PHP, this is the easiest way to get a block of HTML into a string.

public function htmlToString() {
    ob_start();
?>
<!-- Your HTML goes here. -->
<?php
    /* Or 'echo' PHP strings or even function results here. */
    $html = ob_get_contents();
    ob_end_clean();
    return $html;
}

Basically, whatever is echoed between the ob_start() and $html = statements goes into the string.