PHP 함수 get title()

(PHP get title()에서 넘어옴)

1 개요[ | ]

PHP 함수 get_title()
  • URL의 HTML에서 title 추출
<?php
function get_title($url) {
	$str = file_get_contents($url);
	if(strlen($str)>0) {
		$str = trim(preg_replace('/\s+/', ' ', $str));
		preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title);
		return $title[1];
	}
}

echo get_title("http://www.washingtontimes.com/")."\n";
echo get_title("https://en.wikipedia.org/wiki/Guy_Fawkes_mask")."\n";
echo get_title("https://en.wikipedia.org/w/index.php?title=Guy_Fawkes_mask&action=edit")."\n";
echo get_title("https://ko.wikipedia.org/wiki/훈민정음")."\n";
echo get_title("https://ko.wikipedia.org/w/index.php?title=%ED%9B%88%EB%AF%BC%EC%A0%95%EC%9D%8C&action=edit")."\n";
root@zetawiki:~# php get_title.php 
Washington Times - Politics, Breaking News, US and World News
Guy Fawkes mask - Wikipedia, the free encyclopedia
Editing Guy Fawkes mask - Wikipedia, the free encyclopedia
훈민정음 - 위키백과, 우리 모두의 백과사전
훈민정음 편집하기 - 위키백과, 우리 모두의 백과사전

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}