Argh that is some ugly code, when you are writing a lot of HTML into PHP strings use single quotes that way you don't need to escape every double quote in the HTML.
For example:
PHP Code:
$ocfapidata = "<tbody><tr><td class=\"thead\" colspan=\"3\"><a style=\"float:".$stylevar[right]."\" href=\"#top\" ";
// BECOMES:
$ocfapidata = '<tbody><tr><td class="thead" colspan="3"><a style="float:'. $stylevar['right'] .'" href="#top" ';
Doesn't it look so much better?