2013-11-26 3 views
0

동일한 페이지에서 PHP로 변수를 전달하려고합니다.PHP 변수를 html 파일로 전달

<form name="form1" method="POST" action="index.php"> 
<input type="text" name="F1" value="" size="35"> 
</br> 
<input type="submit" name="B1" value="Go!"> 
</form> 

와 PHP 스크립트는 다음과 같습니다 : 양식은

<?php 

     if(isset($_POST['B1'])) 
     { 
     $u=$_POST['F1']; 

      $document=new domDocument('1.0', 'WINDOWS-1251'); 
      $document->loadHTML 
      ('<html> 
       <head> 
        <title></title> 


       </head> 
      <body> 


       echo $u; 


      </body> 
      </html>'); 

      $document->formatOutput=true; 
      $document->encoding='WINDOWS-1251'; 
      $document->saveHTMLFile("output.php"); 

     } 
     ?> 

스크립트는 형태로 decleared 텍스트 영역의 내용을 인쇄하는 "output.php"파일을 생성하기위한 것입니다, 하지만 작동하지 않습니다. 어떻게해야합니까?

감사합니다.

+0

처럼 사용할 수 있습니까? 어떤 오류가 발생합니까? 디버깅을 위해 무엇을 했습니까? –

+0

''작동하지 않는다 '는게 무엇을 의미합니까? 파일이 생성되지 않습니까? 출력 된 텍스트가 올바르지 않습니까? –

+0

'$ document-> loadHTML()'안에서 작은 따옴표를 사용하고 있으므로 실제 변수 값을 사용하지 않을 것입니다. 대신 이중 따옴표로 묶어야합니다. 그 이유는 [documentation] (http://php.net/manual/en/language.types.string.php)를 참조하십시오. –

답변

2

변경이 :

$document->loadHTML 
    ('<html> 
     <head> 
      <title></title> 
     </head> 
     <body> 
      echo $u; 
     </body> 
    </html>'); 

$document->loadHTML 
    ('<html> 
     <head> 
      <title></title> 
     </head> 
     <body> 
      '.$u.' 
     </body> 
    </html>'); 
+0

정말 고마워요! – luaLover

0

또한 무엇을 작동하지 않습니다에게

$document->loadHTML 
    ("<html> 
    <head> 
     <title></title> 
    </head> 
    <body> 
     $u 
    </body> 
    </html>"); 
관련 문제