2017-01-16 7 views
1

PHPコードとHTMLタグの両方を含むPHPファイルがあります。PHPは現在のファイルの一部を新しいファイルに書き込みます

新しいファイルに保存したい部分の実際の内容。

<html> 
<head> 
    <title>PayPal PHP SDK: Transaction Search Results</title> 
    <link href="sdk.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
    <br> 
    <center> 
    <font size=3 color=black face=Verdana><b>Transaction Search Results</b></font> 
    <br><br> 
    <table class="api"> 
<?php //checking for Transaction ID in NVP response 
if(!isset($resArray["L_TRANSACTIONID0"])){ 
?> 
    <tr> 
     <td colspan="6" class="field"> 
      No Transaction Selected 
     </td> 
    </tr> 
<?php 
    }else { 
     $count=0; 
     //counting no.of transaction IDs present in NVP response arrray. 
     while (isset($resArray["L_TRANSACTIONID".$count])) 
      $count++; 
?> 
      <tr> 
      <td colspan="6" class="thinfield"> 
        Results 1 - <?php echo $count; ?> 
      </td> 
     </tr> 
     <tr> 
      <td > 
      </td> 
      <td > 
       <b>ID</b></td> 
      <td > 
       <b>Time</b></td> 
      <td > 
       <b>Status</b></td> 
      <td > 
       <b>Payer Name</b></td> 
      <td > 
       <b>Gross Amount</b></td> 
     </tr> 

<?php 
     $ID=0; 
    while ($count>0) { 
      $transactionID = $resArray["L_TRANSACTIONID".$ID]; 
      $timeStamp = $resArray["L_TIMESTAMP".$ID]; 
      $payerName = $resArray["L_NAME".$ID]; 
      $amount = $resArray["L_AMT".$ID]; 
      $status = $resArray["L_STATUS".$ID]; 
      $count--; $ID++; 
?> 
     <tr> 
      <td><?php echo $ID; ?></td> 
      <td><a id="TransactionDetailsLink0" href="TransactionDetails.php?transactionID=<?php echo $transactionID; ?>"><?php echo $transactionID; ?></a></td> 
      <td><?php echo $timeStamp;?> <!--12/7/2005 9:57:58 AM--></td> 
      <td><?php echo $status;?></td> 
      <td><?php echo $payerName;?></td> 
      <td>USD<?php echo $amount;?></td> 
     </tr> 
<?php }// while 
}//else ?> 

    </table> 
    </center> 
    <a class="home" id="CallsLink" href="index.html">Home</a> 
</body> 
</html> 

私は、HTMLの前に <のようにこれを試してみました。 はその後、エンド

<?php 
$output = ob_get_clean(); 
file_put_contents (time().'response.html', $output);?> 

しかし、結果がで、出力表示が消えているとファイルは作成されません。

+0

出力バッファを開始する必要があります –

+2

ファイルの先頭に 'ob_start()'を忘れていませんか? – rocknrollcanneverdie

+0

はい私はこれを追加しました。誤って質問に残っています。それを更新しました。それでも同じ問題に直面しています。 – Pawan

答えて

2

start the output bufferob_get_clean()の返品が必要です。

<?php 
ob_start(); 
?> 
<html> 
<head> 
    <title>PayPal PHP SDK: Transaction Search Results</title> 
    <link href="sdk.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
    <br> 
    <center> 
.... 
+0

ブラウザに結果を表示して同時にファイルに書き込むことが可能です。 – Pawan

+0

はい。 'ob_get_clean()'を保持している変数を出力することができます。たとえば、 'echo $ output;' –

+0

ありがとうございました。 – Pawan

関連する問題