如何阻止 fwrite 显示在脚本末尾写入的字节数?

How do I stop fwrite from displaying amount of bytes written at end of script?

所以我有一个脚本,它写了几页,最后是一个html确认,页面顶部是写入的字节数,看起来不对。

如何停止显示此信息?

<?php
$filename = "".$page.".html";
$file = @fopen($filename,"x");
if($file)
{
echo fwrite($file,'html content');


fclose($file)

}   


?>
<!DOCTYPE html>
<html>

  <head>

   <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Thank You</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="css/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesnt work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->



  </head>

      <body>

            <div class="row">
       <div class="col-lg-6">

                        <div class="panel-heading">

                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="alert alert-success alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                Thank you, site has been added successfully! <?php echo '<br><a href="http://www.example.com/';echo $filename; echo '">Click here to go to log page</a>'; ?>
                            </div>
<div style="margin-bottom: 10px;"> <a href="dashboard.html"><button class="btn btn-info" type="submit"><h3>Return to dashboard</h3></button></a></div>
                            </div>

                </div>
                <!-- /.col-lg-6 -->
            </div>
            <!-- /.row -->


       <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="js/plugins/metisMenu/metisMenu.min.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="js/sb-admin-2.js"></script>

    <!-- Page-Level Demo Scripts - Notifications - Use for reference -->
    <script>
    // tooltip demo
    $('.tooltip-demo').tooltip({
        selector: "[data-toggle=tooltip]",
        container: "body"
    })

    // popover demo
    $("[data-toggle=popover]")
        .popover()
    </script>

      </body>

    </html>

简单的回答,这一行反映了调用 fwrite 时写入了多少字节:

echo fwrite($file,'html content');

之所以,是fwrite returns这个信息,看文档:http://php.net/manual/de/function.fwrite.php

调用 fwrite 就足够了,没有 echo:

fwrite($file,'html content');

如果您想对此进行扩展,可以将字节数保存在变量中,以在出现错误时触发操作:

$bytes = fwrite($file, $htmlContent);

if (!$bytes && count($htmlContent)) {
  // Not written to file!
}