content()

Gets or sets file content.

Table of Contents
  1. Description
  2. Example

Description

content(string $path): ?string;
content(string $path, string $value, int|string $seal = null): bool;

This function returns the file content as a string if file exists or null if file does not exists. If the $value argument is available and its value is a primitive, this function will replace the file content with the $value value as a string, or it will create the file if it does not exist. If the path already exists but is not a file, then this function will return false. If for some reason the application fails to write the content to the file, then this function will return null.

Example

test(content('.\path\to\file.txt')); // Returns the file content as a string or `null`
test(content('.\path\to\file-1.txt', 'asdf')); // Returns `true`
test(content('.\path\to\file-1.txt', 'asdf', 0600)); // Creates or updates the file content then sets its permission to `0600`
test(content('.\path\to\file-1.txt', 'asdf', '0600')); // Creates or updates the file content then sets its permission to `0600`
test(content('.\path\to\123\file.txt', 'asdf')); // Returns `true` (folder `'.\path\to\123'` will be created automatically)
test(content('.\path\to\123', 'asdf')); // Returns `null` because path `'.\path\to\123'` already exists and is not a file

a()

Converts object to array.

all()

Checks if all items in the data pass the test.

any()

Checks if at least one item in the value passes the test.

b()

Ensures the minimum and maximum value of a value.

c()

Converts text to camel case.

c2f()

Converts class name to file name.

choke()

Allows access at certain intervals.

concat()

Concatenates multiple arrays into one array.

content()

Gets or sets file content.

d()

Loads classes automatically, efficiently.

drop()

Removes meaning-less array items to reduce the size.

e()

Evaluates string to the proper data type.

eat()

Escapes HTML/XML attribute’s value.

f()

Filters out characters from a string.

f2c()

Converts file name to class name.

f2p()

Converts file name to property name.

find()

Gets the first array item that passes the test.

fire()

Executes a callable or a function.

g()

Generates a list of files and/or folders from a folder.

ge()

Greater than or equal to.

get()

Gets values from an array using dot notation access.

h()

Hyphenates current value.

has()

Checks if an array contains a key using dot notation access.

i()

Makes text translatable.

ip()

Gets the client’s IP address.

is()

Filters the data so that only items that pass the test are left.

j()

Gets array items that are not present in the second array.

k()

Generates a filtered list of files and/or folders from a folder.

l()

Converts text to lower case.

let()

Deletes values from an array using dot notation access.

long()

Converts relative URL to full URL.

m()

Normalizes range to a new range.

map()

Creates a new data set from the current data.

move()

Moves a file/folder to a folder.

not()

Filters the data so that only items that does not pass the test are left.

o()

Converts array to object.

p()

Converts text to pascal case.

p2f()

Converts property name to file name.

path()

Normalizes and resolves file/folder path.

pluck()

Returns a new data set contains values from the key on every item.

q()

Counts the data quantity.

s()

Converts value to the string representation of it.

set()

Sets values to an array using dot notation access.

size()

Converts size in bytes to a human readable string format.

status()

Gets current request/response headers and status or sets current response headers and status.

step()

Creates a step sequence of a split pattern.

store()

Moves the uploaded file to a folder.

stream()

Streams the file content chunk by chunk.

t()

Trims value from a delimiter once.

type()

Gets or sets current response type.

u()

Converts text to upper case.

ua()

Gets the client’s user agent string.

v()

Returns a string without the backslash prefix on every regular expression characters.

w()

Converts file name or HTML string to plain text.

x()

Returns a string with the backslash prefix on every regular expression characters.

y()

Converts iterator to array.

z()

Converts PHP values to a compact string of PHP values.

zone()

Gets or sets current application time zone.