PHP | file_get_contents()

There are method for convert any image into bae64 in PHP are as follow :

Using file_get_contents()

The file_get_contents() function is inbuilt function in PHP which is use to read or get data from various file, path, url and so on into a string.

This function is basically uses memory based technology on server end and enhance the performance.

Syntax

file_get_contents(path, include_path, context, start, max_length)

Parameters

path Required. Specifies the path to the file to read

include_path Optional. Set this parameter to '1' if you want to search for the file in the include_path (in php.ini) as well

context Optional Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream. Can be skipped by using NULL.

start Optional. Specifies where in the file to start reading. Negative values count from the end of the file

max_length Optional. Specifies the maximum length of data read. Default is read to EOF

Example

$homepage = file_get_contents("https://www.myinboxhub.co.in/"); echo $homepage;

?>

Output

//Show all data from https://www.myinboxhub.co.in/ page contains in a string format

Example


$text = file_get_contents('readFile.txt'); echo $text;

?>

Output

//Show all data from file This is a testing, Hello World!

Php Related Topic's