PHP怎么创建文件并且写入文字

WBOY
Release: 2016-06-23 13:50:34
Original
1173 people have browsed it

我要封装个方法 创建文件并且写入文字 参数2个 width和height

实行后的效果     
比方说如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));}
Copy after login

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);}
Copy after login


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);
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template