PHP怎么创建文件并且写入文字
程序员文章站
2024-01-25 13:35:04
...
我要封装个方法 创建文件并且写入文字 参数2个 width和height
实行后的效果
比方说如100 300
生成文件名叫s 100300.less
里面内容是
@import "shiying";
@screen_width: 100px;
@screen_height: 300px;
这个函数怎么写。。 红色的要对应哦
Parse error: syntax error, unexpected ';' in D:\wamp\www\ceshi\xieru.php on line 14
报错了 而且这个fileputcontent不能自动生成文件吧。。
实行后的效果
比方说如100 300
生成文件名叫s 100300.less
里面内容是
@import "shiying";
@screen_width: 100px;
@screen_height: 300px;
这个函数怎么写。。 红色的要对应哦
回复讨论(解决方案)
function mkless($width, $height) { $r[] = '@import "shiying";'; $r[] = sprintf('@screen_width:%spx;', $width); $r[] = sprintf('@screen_height:$spx;', $height); file_put_contents("s$width$height.less", join(PHP_EOL, $r));}
function mkless($width, $height) { $r[] = '@import "shiying";'; $r[] = sprintf('@screen_width:%spx;', $width); $r[] = sprintf('@screen_height:$spx;', $height); file_put_contents("s$width$height.less", join(PHP_EOL, $r);}
Parse error: syntax error, unexpected ';' in D:\wamp\www\ceshi\xieru.php on line 14
报错了 而且这个fileputcontent不能自动生成文件吧。。
file_put_contents("s$width$height.less", join(PHP_EOL, $r);
少个括号
file_put_contents() 函数把一个字符串写入文件中。
与依次调用 fopen(),fwrite() 以及 fclose() 功能一样。
语法
file_put_contents(file,data,mode,context)
参数 描述
file 必需。规定要写入数据的文件。如果文件不存在,则创建一个新文件。
....
...
就是个函数调用 的问题
file_put_contents
顺便符上代码
$filename='s100300.less';$date='@import "shiying";@screen_width:100px;@screen_height:300px;';file_put_contents($filename,$date);
上一篇: PHP 获取客户端的相关信息
下一篇: cakephp.acl权限控制,
推荐阅读
-
PHP怎么创建文件并且写入文字
-
php 求教怎么将一数组写入文件aa.txt,而后怎样读取aa.txt文件到一数组
-
ipone5进入网站后台怎么选取图片,并且传给php程序把图片存入项目文件中,图片名称存入数据库字段中?
-
PHP框架Yii2通过内置的方法怎么把配置信息写入到配置文件
-
php 我用fwrite() 写入了一个文件,怎么文件内容全变了?
-
PHP如何创建文件并且写入文字
-
php删除文件后重建,文件创建时间(filectime)未变化怎么解决??
-
PHP 文件操作类创建文件并写入_PHP教程
-
PHP 文件操作类创建文件并写入_PHP教程
-
PHP创建文件,并向文件中写入数据,覆盖,追加的实现代码