1 개요[ | ]
- PHP 함수 get_title()
- URL의 HTML에서 title 추출
PHP
Copy
<?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";
Console
Copy
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 참고[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.
- 분류 댓글:
- PHP (8)
PHP 파일 다운로드 구현 2 (한글 파일명 지원) ― …PHP에서 오라클 DB 사용 ― YoWuPHP 파일 업로드 구현 ― 일리단사오육칠PHP 파일 업로드 구현 ― JmnotePHP 파일 다운로드 구현 2 (한글 파일명 지원) ― AnmkstLib my.php ― 신정섭Lib my.php ― Jmnote로또번호 생성 ―Pinkcrimson