NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - file_get_contents

Trieda

Koreň \ Bez triedy

Metóda - file_get_contents

(PHP 4 >= 4.3.0, PHP 5, PHP 7)

file_get_contents() reads a file and returns its contents as string. The filename can be either a local path (absolute or relative), or a URL (if the fopen-wrappers module is allowed).

Procedurálne

  • function file_get_contents (string $filename, resource $context, int $offset = 0, int $maxlen) : string

Parametre

NázovDátový typPredvolená hodnotaPopis
$filenamestring

The path to the file or URL.

On Windows, make sure that all backslashes are escaped properly.

$contextresource

A context created by stream_context_create(). If a custom context is not needed, the parameter can be skipped by passing null.

$offsetint 0

The offset where the reading starts. Not supported on remote files. If the offset is a negative number, it's treated from the end of the stream and goes backwards.

$maxlenint

The maximum length of the input to be read. The whole file is read by default.

Mávratovej hodnoty

Vracia: string

The file contents if the file can be read, false otherwise

Príklady

<?php
    // Downloads the content of the URL 'https://www.ict.social/test.txt' and stores it in the $content variable, which is then printed.
    $content = file_get_contents('https://www.ict.social/test.txt');
    echo $content;
?>

Súvisiace manuály

        Aktivity