我是PHP新手,想要创建一个用户定义的HTML页面(甚至文本文件),但是当我使用fopen时,在本地文件夹中创建了一个名为0的文件夹,这是我的代码
<?php
$ifilename = "A195-2256";
$filename = $ifilename + ".html";
$myfile = fopen($filename, "w+") or die("Unable to open file!");
$txt = "Some text here";
fwrite($myfile, $txt);
fclose($myfile);
?>
有谁能帮我吗? 您使用的连接操作符是错误的。对于php,您需要使用.
而不是+
操作符。这就是php为您创建名为0的文件夹的原因。带有out扩展名的文件在php的文件I/O函数中被认为是一个文件夹。
$filename = $ifilename + ".html";
更新的代码片段。
$filename = $ifilename . ".html";
查看下面的固定完整版本的代码
<?php
$ifilename = "A195-2256";
$filename = $ifilename .".html";
$myfile = fopen($filename, "w+") or die("Unable to open file!");
$txt = "Some text here";
fwrite($myfile, $txt);
fclose($myfile);
?>
在PHP中使用'。'用于连接字符串,而不是'+'。
$ifilename = "A195-2256";
$filename = $ifilename . ".html";
在你的表达式中,你正在创建一个值0