所以我有一个脚本可以写几个页面,最后是一个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">×</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>
答案 0 :(得分:1)
简单的回答,这一行回应了在调用fwrite时写入的字节数:
echo fwrite($file,'html content');
原因是fwrite返回此信息,请参阅文档: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!
}