2011-02-12 2 views
0

이 코드는 ob_start PHP 함수를 사용합니다. 기본적으로 에코 된 데이터를 html 파일에 저장합니다. 그것은 이전에 작동합니다. 나는 그때 내가 사용하고 있던 php의 버전을 모른다. 하지만 현재 버전은 5.3.0입니다. 나는 그것이 왜 효과가 없을지 설명 할 수 없다. 스크립트가 아래에 작동하고 그냥 HTML 파일에 해당 스크립트의 출력을두고 있기 때문에 : 여기PHP에서 ob_start 함수의 문제점

<?php 
ob_start(); 
?> 
<h2>Customer Payment Summary</h2> 
<a href="pdftransactions.php?acts=customerpay&ofile=<?php echo $customer.' customerpay '.$date; ?>"><img id="tablez" src="../img/system/icons/Oficina-PDF-icon.png"></img></a> 

<?php 
if($amtopay>=$curcred){ 
    $custchange=$amtopay - $curcred; 
    $newcred = 0; 

    echo "Change: ". $custchange."<br/>"; 
    query_database("DELETE FROM sales_transaction WHERE Cust_Name='$customer'", "onstor", $link); 
}else{ 
    query_database("UPDATE customer_credit SET CREDIT='$newcred' WHERE Cust_Name='$customer'", "onstor", $link); 
    echo "Remaining Balance: ". $newcred."<br/>";; 
} 

echo "Customer: ".$customer."<br/>"; 
echo "Amount paid: ". $amtopay. "<br/>"; 
echo "Date: ". $date." ". date('A'); 
close_connection($link); 
?> 

<?php 
file_put_contents('../tmp/customerpay.html', ob_get_contents()); 
?> 

위 코드의 출력입니다 : enter image description here

을하지만 HTML 파일을 검사 할 때 어떤 I file_put_contents에 지정됩니다. 그것은 나에게 이것을 준다. 그리고 나는 왜 그런지 이해하지 못합니다. enter image description here

제 문제는 생산되는 html 파일에서 올바른 출력을 얻는 방법입니다. 스크립트의 끝에

+1

은 그래서 서식 문제입니다, 또는 내용? – Piskvor

+0

내 문제는 생산되는 html의 내용입니다. – user225269

+1

ob_end_clean()을 추가하십시오. ob_get_contents() 문 다음에. –

답변

3

당신이 file_put_contents를을하기 전에 당신은 당신의 출력 버퍼를 종료하지 않습니다 ...

는 다음으로 변경 :

//... 
close_connection($link); 
$contents = ob_get_contents(); 
ob_end_clean(); 

file_put_contents('../tmp/customerpay.html', $contents); 
?> 
+1

또한 오류 로그를 확인하여 문제의 정확한 원인을 확인하십시오. – JamesHalsall