hello world
phpとjsとhtmlでhello worldしてみた。
<?php //print_r($argv); function html($content) { return "<!DOCTYPE html>\n".wrap("html", $content); } function wrap($title,$content, $options=null) { if ($options == null) { return "<$title>\n"." ".$content."</$title>\n"; } else { $res = ""; foreach($options as $key => $value) { $op = "$key"."="."$value"; $res = $res.$op; } return "<$title $res>\n"." ".$content."</$title>\n"; } } function head($content) { return wrap("head", $content); } function body($content) { return wrap("body", $content); } function script($content) { return wrap("script", $content, array("type" => "text/javascript")); } function p($content) { return wrap("p", $content); } // -------------------------------------------- $head = head(" <title>title</title> <meta charset='utf-8' /> <style type='text/css'> p { color: yellow; background-color: black; } </style> "); $script = script(" document.writeln('<p> Hello rorld</p>'); "); $body = body(p("Hello World").$script); $result = html($head.$body); echo $result; ?>
実行すると以下が表示される。
<!DOCTYPE html> <html> <head> <title>title</title> <meta charset='utf-8' /> <style type='text/css'> p { color: yellow; background-color: black; } </style> </head> <body> <p> Hello World</p> <script type=text/javascript> document.writeln('<p> Hello rorld</p>'); </script> </body> </html>