2012-02-17 3 views

答えて

0

私はこれを試して動作します。

<?php 
    $dom = new DOMDocument('1.0', 'UTF-8'); 
    $dom->formatOutput = true; 
    $html = $dom->createElement('html'); 
    $dom->appendChild($html); 

    //head 
    $head = $dom->createElement('head'); 
    $title = $dom->createElement('title'); 
    $title->nodeValue = "title of my page"; 
    $head->appendChild($title); 
    $html->appendChild($head); 


    //body 
    $body = $dom->createElement('body'); 
    $h1 = $dom->createElement('h1'); 
    $h1->nodeValue = "Hello, World"; 
    $body->appendChild($h1); 
    $html->appendChild($body); 

    //form 
    $form = $dom->createElement('form'); 
    $form->setAttribute("action", ""); 
    $form->setAttribute("method", "post"); 

    $checkbox = $dom->createElement("input"); 
    $checkbox->setAttribute("type", "checkbox"); 
    $checkbox->setAttribute("name", "myCheckbox"); 
    $checkbox->setAttribute("value", "someval"); 
    $form->appendChild($checkbox); 

    $body->appendChild($form); 

    echo $dom->saveHTML(); 
?> 
+0

もちろん、足で自分を撃つことができます。私は、このOOPスタイルでプレゼンテーションレイヤを生成することは悪い習慣だと思います –

関連する問題