'; echo "\n\n\n"; echo " $title\n"; echo ' '; echo "\n\n\n"; echo "\n"; echo "$body\n"; echo "
\n

Back to Problem Set index page

\n"; echo "\n"; echo ""; } // Construct title and body-content for page rendering function construct_page ($dollarxr) { $now = date("Y-m-d H:i:s"); $kroner = 100*$dollarxr; $dollars = 100/$dollarxr; $title = "Dollar exchange rate service - $now"; $body = "

Problem Set 5: C - Dollar exchange rate

" ."

Currently ($now) the exchange rate is $dollarxr.

" ."

For \$100.00 you get kr.$kroner

" ."

For kr.100.00 you get \$ $dollars

"; render_page ($title, $body); } // Get the HTML page that contains the dollar exchange rate $content = file_get_contents ("http://se.finance.yahoo.com/m5?a=1&s=USD&t=DKK"); // The pattern to use with the ereg command $pattern = 'USDDKK.+([0-9.]+)'; if ( eregi($pattern,$content,$result) ) { // there is a match $dollarxr = (double)"$result[1]"; construct_page ($dollarxr); } else { # no match; something went wrong! render_page ("Unavailable service", "The service is unavailable!

" ."Please send me an thorarinn@itu.dk."); } ?>