Forum und email
file_get_contents

file_get_contents

(PHP 4 >= 4.3.0, PHP 5)

file_get_contents -- Reads entire file into a string

Popis

string file_get_contents ( string filename [, bool use_include_path [, resource context [, int offset [, int maxlen]]]] )

Identical to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to maxlen bytes. On failure, file_get_contents() will return FALSE.

file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.

Poznámka: If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode().

Poznámka: context parameter can be skipped by NULL.

ChangeLog (záznam změn)

VerzePopis
5.0.0 Added the context support.
5.1.0 Added the offset and maxlen parameters.

Poznámky

Poznámka: Tato funkce je binárně bezpečná.

Tip: S touto funkcí můžete používat URL jako název souboru, pokud je zapnuta volba "fopen wrappers". Pro více detailů o tom, jak specifikovat název souboru, a Npro seznam porporovaných URL protokolů, viz fopen().

Poznámka: Kontextová podpora byla přidána v PHP 5.0.0. Pro popis contexts nahlédněte do Stream Functions.

Varování

Server Microsoft IIS porušuje při používání SSL komunikační protokol tím, že uzavře spojení bez odeslání indikátoru close_notify. PHP to ohlásí jako "SSL: Fatal Protocol Error", když dosáhne konce toku dat. K vyřešení této situace byste mělo snížit úroveň hlášení chyb (error_reporting) tak, aby nezahrnovala varování. PHP 4.3.7 a vyšší dokáže detekovat chybný software IIS, otevřete-li stream za použití wrapperu https:// a bude automaticky potlačovat příslušná varování. Použijete-li však k vytvoření ssl:// socketu funkci fsockopen(), zůstáváte odpovědni za detekci a potlačení varování.