I. Recommendation Method CURL acquisition
<? Php
$ C = curl_init ();
$ Url = 'www .jb51.net ';
Curl_setopt ($ c, CURLOPT_URL, $ url );
Curl_setopt ($ c, CURLOPT_RETURNTRANSFER, 1 );
$ Data = curl_exec ($ c );
Curl_close ($ c );
$ Pos = strpos ($ data, 'utf-8 ');
If ($ pos = false) {$ data = iconv ("gbk", "UTF-8", $ data );}
Preg_match ("/<title> (. *) <\/title>/I", $ data, $ title );
Echo $ title [1];
?>
Ii. Use the file () function
<? Php
$ Lines_array = file ('HTTP: // www.jb51.net /');
$ Lines_string = implode ('', $ lines_array );
$ Pos = strpos ($ lines_string, 'utf-8 ');
If ($ pos = false) {$ lines_string = iconv ("gbk", "UTF-8", $ lines_string );}
Eregi ("<title> (. *) </title>", $ lines_string, $ title );
Echo $ title [1];
?>
3. Use file_get_contents
<? Php
$ Content = file_get_contents ("http://www.jb51.net /");
$ Pos = strpos ($ content, 'utf-8 ');
If ($ pos = false) {$ content = iconv ("gbk", "UTF-8", $ content );}
$ Postb = strpos ($ content, '<title>') + 7;
$ Poste = strpos ($ content, '</title> ');
$ Length = $ poste-$ postb;
Echo substr ($ content, $ postb, $ length );
?>