<?PHP

// This scripts parses a javascript link output and removes bogos layout instructions

// enter you Javascriopt link HERE. This one ist just an example that won't work
$source='http://www.wetter.com/v2/woys2/woys2.js.php?YOURID';

$handle fopen ($source"r");
$contents fread ($handle10000);
fclose ($handle);

// Remove Line Breaks
$contents=preg_replace('/(\r\n|\r|\n)+/'""$contents);

// Remove document.write('...');
$contents=preg_replace("/document.write\('([^\)]*)'\)(;){0,1}/","$1",$contents);

// No need for foreign styles
$contents=preg_replace("/<STYLE>.*<\/STYLE>/","",$contents);

// only img,a,table,tr,td are kept
$contents=strip_tags($contents,'<td> <img> <a> <br> <table> <tr>');

// cleanup table tr and td
$contents=preg_replace("/<((\/){0,1}(td)|(tr)|(table))\ [^>]*>/","<$1>",$contents);

// cleanup img
$contents=preg_replace("/<img[^(src=)]*src=\"([^\"]*)\"[^>]*>/","<img src=\"$1\">",$contents);

// cleanup a
$contents=preg_replace("/<a[^(href=)]*href=\"([^\"]*)\"[^>]*>/","<a href=\"$1\">",$contents);

// schrink > < to ><
$contents=preg_replace("/>\ *</","><",$contents);

// add styles
$contents=preg_replace("/<([a-zA-Z]+)(\ [^>]*)*>/","<$1 $2 class=\"parsed_$1\">",$contents);

// line break after tr, table
$contents=preg_replace("/(<(\/){0,1}((tr)|(table))([^>]*)>)/","$1\n",$contents);

// line break bevor tr, table
$contents=preg_replace("/^(<.*>)(<(\/){0,1}((tr)|(table))([^>]*)>)/","$1\n$2",$contents);

echo 
$contents;

?>