F::write PHP Method

write() public static method

f::write('test.txt', 'hello'); creates a new text file with hello as content create a new file f::write('text.txt', array('test' => 'hello')); creates a new file and encodes the array as json
public static write ( string $file, mixed $content, boolean $append = false ) : boolean
$file string The path for the new file
$content mixed Either a string, an object or an array. Arrays and objects will be serialized.
$append boolean true: append the content to an exisiting file if available. false: overwrite.
return boolean
    public static function write($file, $content, $append = false)
    {
        if (is_array($content) || is_object($content)) {
            $content = serialize($content);
        }
        $mode = $append ? FILE_APPEND | LOCK_EX : LOCK_EX;
        // if the parent directory does not exist, create it
        if (!is_dir(dirname($file))) {
            if (!dir::make(dirname($file))) {
                return false;
            }
        }
        return @file_put_contents($file, $content, $mode) !== false ? true : false;
    }