Found 1466 Articles for PHP

fileatime() function in PHP

Samual Sam
Updated on 24-Jun-2020 08:45:35

56 Views

The fileatime() function returns the last access time of a file. It returns the last accessed time of a file as a UNIX timestamp. it returns false on failure.Syntaxfileatime ( file_path );Parametersfile_path − The path of the file for which the last access time will be found.ReturnThe fileatime() function returns the last accessed time of a file as a UNIX timestamp. it returns false on failure.ExampleOutput1315416291Let us now get the last access time as a date which is in human readable form.Example Live DemoOutputLast access time of the file: September 22 2018 11:23:52

file_put_contents() function in PHP

karthikeya Boyini
Updated on 24-Jun-2020 08:46:01

1K+ Views

The file_put_contents() function writes a string to a file. The function returns the number of bytes that were written to the file, or FALSE on failure.Syntaxfile_put_contents(file_path, data, flags, context)Parametersfile_path − The path of the file.data − Set the data to be written in the file:flags − Specifies how the file is opened or data has to be written:FILE_USE_INCLUDE_PATH − Search for filename in the include directory.FILE_APPEND − If file filename already exists, append the data to the file instead of overwriting it.LOCK_EX − Acquire an exclusive lock on the file while proceeding to the writing.FILE_TEXT − data is written in ... Read More

file_get_contents() function in PHP

Samual Sam
Updated on 24-Jun-2020 08:46:34

618 Views

The file_get_contents() function reads entire file into a string. The file() function reads the entire file in a array, whereas file_get_contents() function reads the entire file into a string.Syntaxfile_get_contents(file_path, flags, context, start_offset, max_length)Parametersfile_path − The path of the file.flags − The value of flags can be any combination of the following flags joined with the binary OR (|) operator.FILE_USE_INCLUDE_PATH − Search for filename in the include directory.FILE_TEXT − If unicode semantics are enabled, the default encoding of the read data is UTF-8. his flag cannot be used with FILE_BINARY.FILE_BINARY − With this flag, the file is read in binary mode. ... Read More

file() function in PHP

karthikeya Boyini
Updated on 24-Jun-2020 08:47:06

178 Views

The file() function reads a file into an array.Syntaxfile(file_path, flag, context)Parametersfile − Path of the file.flag − The optional parameter flags can be one, or more, of the following constants −FILE_USE_INCLUDE_PATH − Search for the file in the include_path.FILE_IGNORE_NEW_LINES − Do not add newline at the end of each array element.FILE_SKIP_EMPTY_LINES − Skip empty lines.FILE_TEXT − The content is returned in UTF-8 encoding. You can specify a different encoding by creating a custom context. This flag cannot be used with FILE_BINARY. This flag is only available since PHP 6.FILE_BINARY − The content is read as binary data. This is the ... Read More

fgetss() function in PHP

Samual Sam
Updated on 24-Jun-2020 08:50:04

73 Views

The fgestss() function gets a line from the file pointer and strip HTML and PHP tags. The fgetss() function returns a string of up to length - 1 bytes read from the file pointed to by handle, with all HTML and PHP code striped. If an error occurs, returns FALSE.Syntaxfgetss(file_path, length, tags)Parametersfile_pointer − The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).length − Length of the datatags − The tags that you don’t want to remove.ReturnThe fgetss() function returns a string of up to length ... Read More

fgets() function in PHP

karthikeya Boyini
Updated on 24-Jun-2020 08:50:48

362 Views

The fgets() function returns a line from a file. It returns a string of up to length - 1 bytes read from the file pointed to by file_pointer.Syntaxfgets (file_pointer, length);Parametersfile_pointer − The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen().length − Reading ends when length - 1 bytes have been read, on a newline, or on EOF (whichever comes first).ReturnThe fgets() function returns a string of up to length - 1 bytes read from the file pointed to by fle_pointer.ExampleThe following is an example. Here, we have a file “one.txt” with ... Read More

fgetcsv() function in PHP

Samual Sam
Updated on 24-Jun-2020 08:51:20

383 Views

The fgetcsv() function parses a line from an open file to check for CSV fields. It returns an array containing the fields read.Syntaxfgetcsv(file_pointer, length, delimiter, enclosure, escape)Parametersfile_pointer − A valid file pointer to a file successfully opened by fopen(), popen(), or fsockopen().length − Maximum length of a line.delimiter − Character that specifies the field separator. Default is comma ( , )enclosure − Set the field enclosure character. Defaults as a double quotation mark.escape − Set the escape character. Defaults as a backslash (\).ReturnThe fgetcsv() function returns an array containing the fields read.ExampleLet’s say we have the following “products.csv” CSV file.laptop, ... Read More

fgetc() function in PHP

karthikeya Boyini
Updated on 24-Jun-2020 08:52:14

121 Views

The fgetc() function gets a character from an open file. It returns false on eof, or a string containing a single character read from the file pointed to by file_pointerSyntaxfgetc(file_pointer)Parametersfile_pointer − The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).ReturnThe fgetc() function returns false on eof, or a string containing a single character read from the file pointed to by file_pointer.ExampleThe following is an example. This reads the first character from the file.The following is the output. Let’s say our file “two.txt” has the text ... Read More

fflush() function in PHP

Samual Sam
Updated on 24-Jun-2020 08:40:21

165 Views

The fflush() function flushes the output to an open file. This function forces a write of all buffered output to the resource pointed to by the file handle.Syntaxfflush(file_pointer)Parametersfile_pointer − Specify the open file stream.ReturnThe fflush() function returns.TRUE on successFALSE on failureExampleOutputtest lineLet us see another example.ExampleOutputJava is a programming language. JavaScript is a scripting language.

feof() function in PHP

karthikeya Boyini
Updated on 24-Jun-2020 08:40:51

193 Views

The feof() function tests for end-of-file on a file pointer. It returns TRUE if the file pointer is at EOF or an error occurs (including socket timeout); otherwise returns FALSE.Syntaxfeo(file_pointer)Parametersfile_pointer − The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose())ReturnThe feof() function returns TRUE if the file pointer is at EOF or an error occurs, otherwise returns FALSE.ExampleOutputFirst line

Advertisements