PHP将当前文件的一部分写入新文件

时间:2017-01-16 15:06:38

标签: php

我有一个包含PHP代码和HTML标签的php文件。

我要保存到新文件的部分的实际内容。

static struct sockaddr_in server_address;
char buf[256];
int numberOfBytes,e;

clientSocketFd = socket(AF_INET,SOCK_STREAM,0);
if(clientSocketFd<0){error("socket() call Failed");}

//Clears allocated space of the sockaddr_in struct before configuration
bzero((char *)&server_address, sizeof(server_address));
server_address.sin_family = AF_INET;
//The IP address being put in here is the same as the one put in the server code, the IP address of the host machine.
if(!inet_aton("XXX.XXX.XXX.XXX",&(server_address.sin_addr))){error("inet_aton() Failed");}

server_address.sin_port = htons(34567);

//Same check as server code, look at the target IP and port
inet_ntop(AF_INET, &server_address.sin_addr,buf,255);
printf("Connecting to %s:%d\n",buf,server_address.sin_port);

//As client, we connect the socketFd for the CLIENT to the address struct of the SERVER
e = connect(clientSocketFd,(struct sockaddr *)&server_address,sizeof(server_address));
if(e<0){error("connect() call Failed");printf("Error code %d\n",e);}

//Connection has now been established and can be referenced through clientSocketFd
printf("CONNECTION ESTABLISHED\n");

//Now send a generic message 
numberOfBytes = write(clientSocketFd,"TESTMESSAGE",strlen(message));
if(numberOfBytes<0){error("write() call Failed");}

bzero(buf,256);
numberOfBytes = read(clientSocketFd,buf,255);
if(numberOfBytes<0){error("read() call Failed");}

printf("%s\n",buf);

return 0;

我试过这个 &LT;就在html之前。 然后到最后

<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>

但结果是,输出显示消失了,没有创建文件。

1 个答案:

答案 0 :(得分:2)

ob_get_clean()需要start the output buffer才能返回内容。

<?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>
....