php get html from url code example

Example 1: php get url with get

$full_url = 'http://'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];

Example 2: download html content from url php

$c = curl_init('https://yourURLhere.com');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
//curl_setopt(... other options you want...)

$html = curl_exec($c);

if (curl_error($c))
    die(curl_error($c));

// Get the status code
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);

curl_close($c);

Example 3: get page url php

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Example 4: turn text file to string php

$fileContent = file_get_contents($url);

Example 5: get url with php

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Example 6: transfer file using file_get_content

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

Tags:

Php Example