get file content code example

Example 1: php get file contents

<?php
file_get_contents("file.txt");
?>

Example 2: php file get content replacing & with &

$myUrl = 'https://www.myurl.com?';
$myArray = [
    'foo' => 'fooString',
    'bar' => 'barString'
];
$myUrl .= http_build_query($myArray,'','&'); // https://www.myurl.com?foo=fooString&bar=barString
$myData = file_get_contents($myUrl);

Example 3: turn text file to string php

$fileContent = file_get_contents($url);

Example 4: transfer file using file_get_content

file_get_contents('http://url/to/upload/handler', false, $context);

Tags:

Php Example