Last active
December 25, 2015 15:49
-
-
Save easychen/7001126 to your computer and use it in GitHub Desktop.
Revisions
-
easychen revised this gist
Oct 16, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,8 +11,8 @@ function get_title_via_url( $url ) if( preg_match( $reg , $content , $out ) ) { $title = $out[1]; if(!is_utf8( $content )) $title = mb_convert_encoding( $title , 'UTF-8' , 'GBK' ); return $title; } return basename( $url ); -
easychen renamed this gist
Oct 16, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
easychen revised this gist
Oct 16, 2013 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,4 +26,5 @@ function is_utf8( $content ) { return $out[1] == 'utf-8'; } } ?> -
easychen created this gist
Oct 16, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ <?php function get_title_via_url( $url ) { // 抓取前1024个字节 $context=array('http' => array ('header'=> 'Range: bytes=0-1024' )); $xcontext = stream_context_create($context); $content = strtolower( file_get_contents( $url , FALSE,$xcontext ) ); $reg = '/<title>(.+?)<\/title>/is'; if( preg_match( $reg , $content , $out ) ) { $title = $out[1]; if(!is_utf8( $content )) $title = mb_convert_encoding( $title , 'UTF-8' , 'GBK' ); return $title; } return basename( $url ); } function is_utf8( $content ) { $content = strtolower($content); $reg = '/<meta.+?charset=[\'"]?([a-z0-9\-]+)[\'"]/is'; if(preg_match( $reg , $content , $out )) { return $out[1] == 'utf-8'; } }