后端开发|php教程
PHP,获取网页标题,CURL,file函数,file_get_contents函数
后端开发-php教程
A、推荐方法 CURL获取
<?php
$c = curl_init();
$url = ‘’;
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(“/
echo $title[1];
?>
B、使用file()函数
<?php
$lines_array = file(‘/’);
$lines_string = implode(”, $lines_array);
$pos = strpos($lines_string,’utf-8′);
if($pos===false){$lines_string = iconv(“gbk”,”utf-8″,$lines_string);}
eregi(“
echo $title[1];
?>
C、使用file_get_contents
<?php
$content=file_get_contents(“/”);
$pos = strpos($content,’utf-8′);
if($pos===false){$content = iconv(“gbk”,”utf-8″,$content);}
$postb=strpos($content,’
$poste=strpos($content,’
$length=$poste-$postb;
echo substr($content,$postb,$length);
?>
php开发的商城系统源码下载,vscode的md如果保存,ubuntu ios下载,tomcat报jar错,铁丝小爬虫,php获取qq空间,seo不想要显示的网址,导航网站 程序,dedecms 会员模板lzw
如果觉得《PHP获取网页标题的3种实现方法代码实例【PHP】》对你有帮助,请点赞、收藏,并留下你的观点哦!