2011年8月4日木曜日

[PHP]Webページのタイトルを取得する

  1. /** 
  2.  * Webページのタイトルを取得する 
  3.  */  
  4. function getPageTitle( $url )  
  5. {  
  6.     $html = file_get_contents($url);  
  7.     $html = mb_convert_encoding($html, mb_internal_encoding(), "auto" );  
  8.     if ( preg_match( "/<title>(.*?)<\/title>/i"$html$match) )  
  9.     {  
  10.         return $match[1];  
  11.     }  
  12.     else  
  13.     {  
  14.         return "";  
  15.     }  
  16. }