Learn how to use file_put_contents() function in PHP
Example of the PHP file_put_contents() function
Description
Syntax of file_put_contents() PHP
file_put_contents(file_name,data_to_file,[file_mode,[file_context]])
It writes the data to the file .It overwrites the previous contents.
file_mode mode for the file writing with the constant values
Code & Example of file_put_contents() PHP
<?php
$string1=file_get_contents("c:/rose1/ram.txt");
echo $string1;
$data1="\nindia is my country";
file_put_contents("c:/rose1/ram.txt",$data1);
$string2=file_get_contents("c:/rose1/ram.txt");
echo "<br>".$string2;
?>
Output
1.
welcome to rosindia welcome to rosindia welcome to rosindia
india is my country
2.
india is my country
india is my country
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.