Example: file_get_contents()


OpenWeather https://openweathermap.org/

Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/eckfordd/public_html/citw185/examples/content.php on line 13

Warning: file_get_contents(https://api.openweathermap.org/data/2.5/weather?q=London&appid=your_api_key): Failed to open stream: no suitable wrapper could be found in /home/eckfordd/public_html/citw185/examples/content.php on line 13

JSONPlaceholder https://jsonplaceholder.typicode.com/

Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/eckfordd/public_html/citw185/examples/content.php on line 23

Warning: file_get_contents(https://jsonplaceholder.typicode.com/posts/1): Failed to open stream: no suitable wrapper could be found in /home/eckfordd/public_html/citw185/examples/content.php on line 23

OpenStreetMap API https://jsonplaceholder.typicode.com/

Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/eckfordd/public_html/citw185/examples/content.php on line 33

Warning: file_get_contents(https://nominatim.openstreetmap.org/search?q=London&format=json): Failed to open stream: no suitable wrapper could be found in /home/eckfordd/public_html/citw185/examples/content.php on line 33

Data.gov https://data.gov/

Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/eckfordd/public_html/citw185/examples/content.php on line 43

Warning: file_get_contents(https://example.com/dataset.csv): Failed to open stream: no suitable wrapper could be found in /home/eckfordd/public_html/citw185/examples/content.php on line 43

Github https://github.com/

Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/eckfordd/public_html/citw185/examples/content.php on line 53

Warning: file_get_contents(https://raw.githubusercontent.com/user/repo/main/data.txt): Failed to open stream: no suitable wrapper could be found in /home/eckfordd/public_html/citw185/examples/content.php on line 53

file_get_contents is not allowed on this host.


 

CODE FOLLOWS

<?php

    
include('includes/header.php');

    echo(
"<h2>Example: file_get_contents() </h2>");

    
ini_set('display_errors'1);
    echo(
"<br>");
    echo 
"OpenWeather" " ";
    echo(
'https://openweathermap.org/');
    echo(
"<br>");
    
$api_url "https://api.openweathermap.org/data/2.5/weather?q=London&appid=your_api_key";
    
$data file_get_contents($api_url);

    
$data strip_tags($data);
    echo(
$data);

    echo(
"<br>");
    echo 
"JSONPlaceholder"." ";
    echo 
"https://jsonplaceholder.typicode.com/";
    echo(
"<br>");
    
$json_url "https://jsonplaceholder.typicode.com/posts/1";
    
$json_data file_get_contents($json_url);

    
$json_data strip_tags($json_data);
    echo(
$json_data);

    echo(
"<br>");
    echo 
" OpenStreetMap API"." ";
    echo 
"https://jsonplaceholder.typicode.com/";
    echo(
"<br>");
    
$map_url "https://nominatim.openstreetmap.org/search?q=London&format=json";
    
$map_data file_get_contents($map_url);

    
$map_data strip_tags($map_data);
    echo(
$map_data);

    echo(
"<br>");
    echo 
"Data.gov"." ";
    echo 
"https://data.gov/";
    echo(
"<br>");
    
$csv_url "https://example.com/dataset.csv";
    
$csv_data file_get_contents($csv_url);

    
$csv_data strip_tags($map_data);
    echo(
$csv_data);

    echo(
"<br>");
    echo 
"Github"." ";
    echo 
"https://github.com/";
    echo(
"<br>");
    
$raw_url "https://raw.githubusercontent.com/user/repo/main/data.txt";
    
$raw_data file_get_contents($raw_url);

    
$raw_data strip_tags($map_data);
    echo(
$raw_data);

    
// Output information about allow_url_fopen:
    
if (ini_get('allow_url_fopen') == 1)
    {
        echo 
'<p style="color: #0A0;">file_get_contents is allowed on this host.</p>';
        echo(
"<br>");
    }
    else
    {
        echo 
'<p style="color: #A00;">file_get_contents is not allowed on this host.</p>';
        echo(
"<br>");
    }

    include(
'includes/footer.php');
?>