Php 为什么不是';我的朋友不工作吗?
合在一起是一个程序,旨在查看一个包含假日的“csv”文件,允许某人选择一个标有数字的按钮,然后将随机选择的假日写入文件。它不起作用了。有什么帮助吗?具体来说,“choose.php”不起作用,并且在启用ini_设置等时没有收到任何错误 HTML文件:Php 为什么不是';我的朋友不工作吗?,php,fopen,fread,Php,Fopen,Fread,合在一起是一个程序,旨在查看一个包含假日的“csv”文件,允许某人选择一个标有数字的按钮,然后将随机选择的假日写入文件。它不起作用了。有什么帮助吗?具体来说,“choose.php”不起作用,并且在启用ini_设置等时没有收到任何错误 HTML文件: <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script&g
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
function start(){
$.ajax({
url:"cgi-bin/php/holiday/start.php",
success:function(code){
$("div#content").html(code);
}
});
}
function choose(link){
var data_id = $(link).attr('rel');
var post = {
id : data_id
}
$.ajax({
url:"cgi-bin/php/holiday/choose.php",
data:post,
method:"POST",
success:function(code){
$("div#content").html(code);
}
});
}
$(document).ready(function(){
start();
});
</script>
</head>
<body>
<header id='header'></header>
<div id='content'></div>
<div id='footer'></div>
</body>
</html>
csv/choices为空fread()
需要第二个参数,即要读取的字节数。如果要读取整个文件,可以使用filesize()
函数:
$holidays = explode(',',fread($file, filesize($file)));
但是,如果您想读取整个文件,可以使用file\u get\u contents()
您可以使用以下命令重写该文件:
file_put_contents("csv/index.csv", implode(',', $holidays));
fread()
需要两个参数,第二个参数是要读取的字节数。为什么不使用file\u get\u contents()
而不是fopen/fread/fclose`?谢谢。你完美地回答了我的问题!认可的
christmas,chinese new year
$holidays = explode(',',fread($file, filesize($file)));
$holidays = explode(',', file_get_contents("csv/index.csv"));
file_put_contents("csv/index.csv", implode(',', $holidays));