Rodhos Soft

備忘録を兼ねた技術的なメモです。Rofhos SoftではiOSアプリ開発を中心としてAndroid, Webサービス等の開発を承っております。まずはご相談下さい。

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>