사이트 내 전체검색
PHP
유투브나 기타 사이트등 정보를 읽어오기
프리이미지
https://cmd.kr/php/892 URL이 복사되었습니다.

본문

<?php

 

if(!function_exists('get_html_from_url')) {

function get_html_from_url($url){

 

if (!function_exists('curl_init')) return $html = file_get_contents($url);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_HEADER, 0); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');

$html = curl_exec($ch);

curl_close($ch);

return $html;

}

}

 

if(!function_exists('get_og_from_html')) {

function get_og_from_html($html){

$enc = mb_detect_encoding($html, array("UTF-8", "EUC-KR", "SJIS"));

libxml_use_internal_errors(true);

$doc = new DomDocument();

$doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', $enc));

$xpath = new DOMXPath($doc);

$query = '//*/meta[starts-with(@property, \'og:\')]';

$metas = $xpath->query($query);

$og = array();

foreach ($metas as $meta) {

$property = $meta->getAttribute('property');

$content = $meta->getAttribute('content');

$og[$property] = $content;

}

return $og;

}

}

 

if(!function_exists('get_og_from_url')) {

function get_og_from_url($url){

$html = get_html_from_url($url);

if($html) return get_og_from_html($html);

else return false;

}

}

 

 

$url="https://www.youtube.com/watch?v=iutBLfcszEc";

$url="https://www.youtube.com/watch?v=HbAXjxjY58M";

$og = get_og_from_url($url);

$arr=array();

if(isset($og['og:video:url'])) $arr[1] = str_replace("autoplay=1", "autoplay=0", $og['og:video:url']);

if(isset($og['og:image'])) $arr[2] = $og['og:image'];

if(isset($og['og:title'])) $arr[3] = addslashes($og['og:title']);

if(isset($og['og:description'])) $arr[4] = addslashes($og['og:description']);

if(isset($og['og:site_name'])) $arr[5] = addslashes($og['og:site_name']);

 

echo "<xmp>";

var_dump($arr);

?>

 

 

array(5) {

  [1]=>

  string(57) "http://www.youtube.com/v/HbAXjxjY58M?version=3&autohide=1"

  [2]=>

  string(52) "https://i.ytimg.com/vi/HbAXjxjY58M/maxresdefault.jpg"

  [3]=>

  string(84) "격투기 여자 선수 잔인한 KO 넉다운 명장면 모음 혐오 주의 ㄷㄷ"

  [4]=>

  string(370) "UFC, 복싱, 격투기 MMA 여자 선수들의 다양한 KO 넉다운 명장면 모음을 만들어봤습니다! 남자선수들 못지 않은 화끈한 KO 영상들이 참 많더라구요. 근데 영상 후반쯤에 글러브에 귀가 거의 반이상 찢어진 부상이 ㄷㄷ 아무쪼록 운동하실때 무리하지 마시고 안전하게 하시길 바래요....."

  [5]=>

  string(7) "YouTube"

}

 

댓글목록

등록된 댓글이 없습니다.

PHP
871 (2/18P)

Search

Copyright © Cmd 명령어 3.22.71.188