How does PHP create a file and write text?

Source: Internet
Author: User
Tags parse error
PHP: how to create a file and write text? I want to encapsulate a method to create a file and write two width and height parameters to the text.

Effect after implementation
For example, 100 300

The generated file name is s 100300. less.

The content is
@ Import "shiying ";
@ Screen_width: 100px;
@ Screen_height: 300px;


How to write this function .. Red must match


Reply to discussion (solution)

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
An error is reported, and the fileputcontent cannot generate files automatically ..

File_put_contents ("s $ width $ height. less", join (PHP_EOL, $ r );
Parentheses

The file_put_contents () function writes a string to a file.

It is the same as calling the fopen (), fwrite (), and fclose () functions in turn.
Syntax

File_put_contents (file, data, mode, context)

Parameter description
File is required. Specifies the file to write data. If the file does not exist, create a new file.
....
...

Is a function call problem.

File_put_contents

By the way, the code

$filename='s100300.less';$date='@import "shiying";@screen_width:100px;@screen_height:300px;';file_put_contents($filename,$date);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.