Skip to content

Instantly share code, notes, and snippets.

@teru01
Created November 13, 2018 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teru01/4b00bb0a0a56724ed96d401ec04e97ee to your computer and use it in GitHub Desktop.
Save teru01/4b00bb0a0a56724ed96d401ec04e97ee to your computer and use it in GitHub Desktop.
<?php
$url = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$file = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
// $file_array = explode("\n\r", $file, 2);
// $header_array = explode("\n", $file_array[0]);
// foreach($header_array as $header_value) {
// $header_pieces = explode(':', $header_value);
// if(count($header_pieces) == 2) {
// $headers[$header_pieces[0]] = trim($header_pieces[1]);
// }
// }
// $ary = explode('\/', $url);
// $filename_with_ext = end($ary);
// preg_match('/.*\/(.*)\.(png|jpg|jpeg|gif|)$/i', $filename_with_ext, $match);
// $filename = $match[1];
// function myUrlMatch($url){
// preg_match('/.*\/(.*)\.(png|jpg|jpeg|gif|)$/i', $url, $match);
// return $match[1] ?? null;
// }
// $a = myurlmatch("https://example.com/hoge.JPG");
// $b = myurlmatch("http://example.com/foo/bar/hoge.png");
// $c = myurlmatch("http://example.com/2018.11.13foo_bar.GIF");
// $d = myurlmatch("https://example.com/hoge.pdf");
$hoge = "hoge";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment