<?php  
 // send wml headers 
 header("Content-type: text/vnd.wap.wml");  
 echo "<?xml version=\"1.0\"?>";  
 echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\""  
    . " \"http://www.wapforum.org/DTD/wml_1.1.xml\">"; 
 ?> 
 
 <wml> 
	 <card id="card1" title="Taoide mara ba Atha Cliath"> 
   <p> 
     <?php  
	    
	    
 // format and output date 
     $the_date = date("M d Y"); 
     print $the_date; 
     print "<br/>Welcome to Reclaim the Sea Wap Site!";  
     $ch = curl_init();
     $timeout = 5; // set to zero for no timeout
     curl_setopt ($ch, CURLOPT_URL, 'http://www.pol.ac.uk/ntslf/tides/?port=0072');
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
     $tide_page = curl_exec($ch);
     curl_close($ch);
     
     
     // just keep everything after the "Predictions DO NOT include meteorological effects" text
     $page = strstr($tide_page, 'Predictions DO NOT include meteorological effects');
     //find where the forecast table starts
     $table_start = strpos($page, '<table>');
	     //find where the <table> ends
		     //need to add 8 to advance past the </table> tag
	     $table_end = strpos($page, '</table>') + 8;
     //and get the slice of $ page that holds the table
     $forecast = substr($page, $table_start, $table_end - $table_start);
     //print the forecast;
     Print "<p>";
	     Print "Taoide mara ba Atha Cliath<br />";
	     print "<table columns=\"2\">";
	       
	     $max = 200;
	     function truncate_string($forecast,$max)
	     {
	     if(strlen($forecast)>$max)
	     {
	     $forecast = substr($forecast,153,$max);
	     $i = strrpos($forecast," ");
	     $forecast = substr($forecast,153,$i);
	     $forecast = $forecast."";
	     }
	     return $forecast;
	     }
	     $text = truncate_string($forecast,1900);
	     
	   
	    print $text;
print "</table>";
     
     ?> 
     
   </p> 
 </card> 
 </wml>