file_put_contents() Function in PHP
file_put_contents() is another built in PHP function which is used mainly to write a string inside a file. The main task performed by the file put command is that it identifies the file in which the data will be written by the user and if the file exists it will add the data to the file but if the file doesn't exist it will automatically create a new one.
file_put_contents function contains multiple parameter which is necessary to be added in order to run the function properly i.e developer has to assign the path of file on which that data will be recorded and the data to be recorded as parameters in the file_put_contents function and as result the function will return the number of bytes of data that has been recorded in file if the writing of file is successful else it will return FALSE if the writing of data fails.
the file_put_contents ( ) function mainly accepts two , major parameters ( $file, $data ) this function is used to return the number of bytes of data that has been written inside the file if the process succeed else it will return false
Errors - one of the major disadvantage of using this function is that it fails to write inside the file if the location of directory or directory name is invalid and sometimes file_put_contents () function returns a non-Boolean character instead of false which is also equivalent to Boolean false.
Here in this program we have declared file_put_contents() and inside the $file parameter we have provided the location of file hello_world from and in the $data parameter we have provided the data to write inside the file
content of two files appended successfully
Here in this program we have declared $file variable to add the location of the file append.txt and we have declared another variable $apnd to add the data inside the file, now we have used the file_put_contents() function with $file and $apnd as parameters we have append our file with data