1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > PHP中使用CURL获取页面title例子

PHP中使用CURL获取页面title例子

时间:2020-07-31 14:54:19

相关推荐

PHP中使用CURL获取页面title例子

php教程|php手册

PHP,CURL,获取页面title例子

php教程-php手册

packetdotnet 源码,vscode制作文本编辑器,ubuntu开在开机,tomcat处理高并发请求,爬虫证书错误,如何安装php5,吉安互联网seo口碑推荐lzw

这篇文章主要介绍了PHP中使用CURL获取页面title例子,本文使用正则实现获取页面title、页面编码、head标签中的内容,需要的朋友可以参考下

qq开放源码,ubuntu12.10上,tomcat9找不到jre,各种小爬虫图案,服务端调用api php,宁海优化seolzw

个人博客php系统源码下载,ubuntu关闭自动登录,爬虫木箱刷桐油,ksweb搭建php,运城seo培lzw

通过PHP获取页面title内容的实战演示:

范例代码:

复制代码 代码如下:

<?php

/*

功能: 取得 URL 页面上的

内容<p>参数:$_POST[‘url’]<p>*/</p><p>// 设置最长执行的秒数<p>ini_set (“expect.timeout”, 30);<p>set_time_limit(30);</p><p>// 检查 URL<p>if(!isset($_POST[‘url’]) || $_POST[‘url’] == ”){<p>echo “URL 错误”;<p>exit;<p>}</p><p>/* 取得 URL 页面数据 */<p>// 初始化 CURL<p>$ch = curl_init();</p><p>// 设置 URL<p>curl_setopt($ch, CURLOPT_URL, $_POST[‘url’]);<p>// 让 curl_exec() 获取的信息以数据流的形式返回,而不是直接输出。<p>curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);<p>// 在发起连接前等待的时间,如果设置为0,则不等待<p>curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);<p>// 设置 CURL 最长执行的秒数<p>curl_setopt ($ch, CURLOPT_TIMEOUT, 30);</p><p>// 尝试取得文件内容<p>$store = curl_exec ($ch);</p><p>// 检查文件是否正确取得<p>if (curl_errno($ch)){<p>echo “无法取得 URL 数据”;<p>//echo curl_error($ch);/*显示错误信息*/<p>exit;<p>}</p><p>// 关闭 CURL<p>curl_close($ch);</p><p>// 解析 HTML 的 区段<p>preg_match(“/(.*)/smUi”,$store, $htmlHeaders);<p>if(!count($htmlHeaders)){<p>echo “无法解析数据中的 区段”;<p>exit;<p>}</p><p>// 取得 中 meta 设置的编码格式<p>if(preg_match(“/]*http-equiv[^>]*charset=(.*)(\”|’)/Ui”,$htmlHeaders[1], $results)){<p>$charset = $results[1];<p>}else{<p>$charset = “None”;<p>}</p><p>// 取得</p><p><title>中的文字<p>if(preg_match(“/<title>(.*)/Ui”,$htmlHeaders[1], $htmlTitles)){<p>if(!count($htmlTitles)){<p>echo “无法解析<title>的内容”;<p>exit;<p>}<p>// 将</p><p><title>的文字编码格式转成 UTF-8<p>if($charset == “None”){<p>$title=$htmlTitles[1];<p>}else{<p>$title=iconv($charset, “UTF-8”, $htmlTitles[1]);<p>}<p>echo $title;<p>}<p>,</p><p></p></p> </div> <div class="keywords"> </div> <div class="tips">本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。</div> </div> <script>news_one();</script> <dl class="plbox" id="comments"> <dt>网友评论</dt> <dd> <textarea class="plcc">文明上网理性发言</textarea> <button class="sendpl">发表评论</button> <div class="pl_tips">网友评论仅供其表达个人看法,并不表明网站立场。</div> <div class="b10"></div> <ol class="pllist"> </ol> </dd> </dl> <script> $(".plcc").focus(function(){ if($('.plcc').val()=='文明上网理性发言') $('.plcc').val(''); }); $(".sendpl").click(function(){ var plcc=$('.plcc').val(),plcs=$('<p>'+plcc+'</p>').text(); if(plcs!='' && plcs!='文明上网理性发言'){ $('.pllist').prepend('<li><img src="https://1200zi.500zi.com/statics/images/member/avatar.jpg" /><span class="adtime">2024-07-05 15:05</span><span class="plname">匿名309819086</span><span class="ipadd">[网友]<i>0.0.0.0</i></span><div class="pldata">'+plcs+' <font color="gray">(审核中)</font></div><div class="support"><span class="s1">顶0</span><span class="s2">踩0</span></div><div class="clear"></div></li>'); $.post("https://1200zi.500zi.com/comment.php",{"commentid":"content_1-67824646-1","title":"PHP%E4%B8%AD%E4%BD%BF%E7%94%A8CURL%E8%8E%B7%E5%8F%96%E9%A1%B5%E9%9D%A2title%E4%BE%8B%E5%AD%90","content":plcs,"token":"bacb91536ae23e1448a1b051c61523c4"}); } }); </script> <script>show(3);</script> <div class="list mt20"> <div class="listTit"><span></span>相关阅读</div> <dl> <dt><a href="https://1200zi.500zi.com/content/14/617/knM3W6652A.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/14/617/bcb355f1d9885b98a19f24d413bc6dd4.jpg" alt="php curl获取title标题乱码怎么办" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/content/14/617/knM3W6652A.html" target="_blank">php curl获取title标题乱码怎么办</a></p> <p class="des"></p> <p class="key"> <span>2019-11-21</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/content/15/955/KnVW4500dp.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/15/955/d782df33e4db150c98d84a2f1c9cf805.jpg" alt="php curl加密获取数据 PHP利用Curl模拟登录并获取数据例子" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/content/15/955/KnVW4500dp.html" target="_blank">php curl加密获取数据 PHP利用Curl模拟登录并获取数据例子</a></p> <p class="des"></p> <p class="key"> <span>2023-02-24</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/content/14/557/j21oNRxqny.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/14/557/82def3407f018c68492df01aff3ac1a0.jpg" alt="PHP中使用CURL伪造来路抓取页面或文件【PHP】" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/content/14/557/j21oNRxqny.html" target="_blank">PHP中使用CURL伪造来路抓取页面或文件【PHP】</a></p> <p class="des"></p> <p class="key"> <span>2020-01-06</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/content/14/589/j21oeW50ny.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/14/589/a8d1d247d1cc524d01024092e9383d19.jpg" alt="PHP中使用CURL请求页面 使用fiddler进行抓包" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/content/14/589/j21oeW50ny.html" target="_blank">PHP中使用CURL请求页面 使用fiddler进行抓包</a></p> <p class="des"></p> <p class="key"> <span>2022-02-10</span> <span></span> </p> </dd> </dl> </div> </div> <div class="sideRight"> <script>news_two();</script> <div class="rightNews mt20"> <div class="rightTit"><span></span>最近发布</div> <div class="rightNewsList"> <dl> <dt><a href="https://1200zi.500zi.com/html/2024/0704/1m29zjXBVk.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/2024/07/04/dd706c58ebed5d4fd963306d5f09d4f0.jpg" alt="四季之美:中考优秀作文1200字四季的感动" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/html/2024/0704/1m29zjXBVk.html" target="_blank">四季之美:中考优秀作文1200字四季的感动</a></p> <p class="key"> <span>2024-07-04</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/html/2024/0704/y426zkx2z1.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/2024/07/04/405e33ac852e42fa506f98818ab0548e.jpg" alt="月光下的村庄:初三散文1200字" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/html/2024/0704/y426zkx2z1.html" target="_blank">月光下的村庄:初三散文1200字</a></p> <p class="key"> <span>2024-07-04</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/html/2024/0704/OP2GE3rnJM.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/2024/07/04/e373e23ba6c8c95fdb866091c2515a79.jpg" alt="感恩之心 感谢您的存在——1200字作文素材大全" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/html/2024/0704/OP2GE3rnJM.html" target="_blank">感恩之心 感谢您的存在——1200字作文素材大全</a></p> <p class="key"> <span>2024-07-04</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/html/2024/0704/mMnZM1xBOR.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/2024/07/04/b77a36fe07f049cc1539df3e38811912.jpg" alt="绑架大明星:自我救赎与真相启示录" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/html/2024/0704/mMnZM1xBOR.html" target="_blank">绑架大明星:自我救赎与真相启示录</a></p> <p class="key"> <span>2024-07-04</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/html/2024/0704/JRd0PaqdLv.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/2024/07/04/a9b4c36ab561881a0a5d62bb817869f0.jpg" alt="探寻海之女的故事:一段1200字的作文" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/html/2024/0704/JRd0PaqdLv.html" target="_blank">探寻海之女的故事:一段1200字的作文</a></p> <p class="key"> <span>2024-07-04</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/html/2024/0704/g82jNkk2kZ.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/2024/07/04/18aa8f09bb316329426442e63e02a6e7.jpg" alt="可爱的小狗 1200字作文" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/html/2024/0704/g82jNkk2kZ.html" target="_blank">可爱的小狗 1200字作文</a></p> <p class="key"> <span>2024-07-04</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/html/2024/0704/E6dRLRQB3e.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/2024/07/04/eef4118401a613e5b54134f641e2d4c0.jpg" alt="中国汉字文化的世界影响:高三想象作文1200字" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/html/2024/0704/E6dRLRQB3e.html" target="_blank">中国汉字文化的世界影响:高三想象作文1200字</a></p> <p class="key"> <span>2024-07-04</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/html/2024/0704/8y2DRgOngL.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/2024/07/04/76f65f3e1200762cc2d71046ffd0d44d.jpg" alt="修养之道:探索人生的1200字篇章" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/html/2024/0704/8y2DRgOngL.html" target="_blank">修养之道:探索人生的1200字篇章</a></p> <p class="key"> <span>2024-07-04</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/html/2024/0704/lGnkLDPdoY.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/2024/07/04/add8d3ab45c6ce1d0a22103bff771e48.jpg" alt="孤独的力量:探讨孤独如何塑造不朽的作品" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/html/2024/0704/lGnkLDPdoY.html" target="_blank">孤独的力量:探讨孤独如何塑造不朽的作品</a></p> <p class="key"> <span>2024-07-04</span> <span></span> </p> </dd> </dl> <dl> <dt><a href="https://1200zi.500zi.com/html/2024/0704/ZVdQ5D7db1.html" target="_blank"><img src="https://1200zi.500zi.com/uploadfile/img/2024/07/04/f616097dbdac0746b6385a1cc4f346b8.jpg" alt="留在我心底 1200字" width="230" height="150" /></a></dt> <dd> <p class="tit"><a href="https://1200zi.500zi.com/html/2024/0704/ZVdQ5D7db1.html" target="_blank">留在我心底 1200字</a></p> <p class="key"> <span>2024-07-04</span> <span></span> </p> </dd> </dl> </div> </div> <div class="rightClass mt20"> <div class="rightTit"><span></span>推荐专题</div> <div class="txt"> <a href="https://1200zi.500zi.com/zt/1/0/zxsczw1200z.html" title="走向深处作文1200字">走向深处作文1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/smsb1200z.html" title="生命随笔1200字">生命随笔1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/gycxzw1200z677.html" title="关于除夕作文1200字">关于除夕作文1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/jdzw1200zcz.html" title="禁毒征文1200字初中">禁毒征文1200字初中</a> <a href="https://1200zi.500zi.com/zt/1/0/lqdllw1200z.html" title="篮球锻炼论文1200字">篮球锻炼论文1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/xj1200zzy.html" title="写景1200字左右">写景1200字左右</a> <a href="https://1200zi.500zi.com/zt/1/1/hjjbxz1200z.html" title="话剧剧本写作1200字">话剧剧本写作1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/fzsw1200z.html" title="风筝散文1200字">风筝散文1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/1200zkplwz.html" title="1200字科普类文章">1200字科普类文章</a> <a href="https://1200zi.500zi.com/zt/1/0/lgk1200z.html" title="论高考1200字">论高考1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/jyzt1200z.html" title="节约主题1200字">节约主题1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/wmqdnr1200z.html" title="文明劝导内容1200字">文明劝导内容1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/flbwcc1200z.html" title="法律伴我成长1200字">法律伴我成长1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/jyx1200zlw.html" title="教育学1200字论文">教育学1200字论文</a> <a href="https://1200zi.500zi.com/zt/1/0/xmgs1200z.html" title="兄妹故事1200字">兄妹故事1200字</a> </div> </div> </div> </div> <script>show(4);</script> <div class="footer"> <div class="footLinks"> <div class="footLink"> <div class="tit">猜你喜欢:</div> <div class="txt txtTwo"> <a href="https://1200zi.500zi.com/zt/1/1/xxlmzw1200z.html" title="学校礼貌作文1200字">学校礼貌作文1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/xgs1200z817.html" title="写故事1200字">写故事1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/yd1200zzw.html" title="元旦1200字作文">元旦1200字作文</a> <a href="https://1200zi.500zi.com/zt/1/0/dxgmzl1200z.html" title="大学革命之旅1200字">大学革命之旅1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/cwwd1200zsx.html" title="春晚舞蹈1200字赏析">春晚舞蹈1200字赏析</a> <a href="https://1200zi.500zi.com/zt/1/1/qbf1200zzw.html" title="请播放1200字作文">请播放1200字作文</a> <a href="https://1200zi.500zi.com/zt/1/0/yjykc1200z.html" title="演讲与口才1200字">演讲与口才1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/gyjddzw1200z.html" title="关于禁毒的作文1200字">关于禁毒的作文1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/zzywyjg1200z.html" title="字在语文演讲稿1200字">字在语文演讲稿1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/ggzdhg1200z.html" title="鬼谷子读后感1200字">鬼谷子读后感1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/yglxdzw1200z.html" title="有关理想的作文1200字">有关理想的作文1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/dsgs1200zdx.html" title="党史故事1200字大学">党史故事1200字大学</a> <a href="https://1200zi.500zi.com/zt/1/0/jt1200z826.html" title="检讨(1200字)">检讨(1200字)</a> <a href="https://1200zi.500zi.com/zt/1/1/n1200zydj495.html" title="年1200字要多久">年1200字要多久</a> <a href="https://1200zi.500zi.com/zt/1/0/zxsczw1200z.html" title="走向深处作文1200字">走向深处作文1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/gmzyp1200z.html" title="《革命者》影评1200字">《革命者》影评1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/aqs1200z.html" title="艾青诗1200字">艾青诗1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/myxzw1200zkt.html" title="猫优秀作文1200字开头">猫优秀作文1200字开头</a> <a href="https://1200zi.500zi.com/zt/1/1/xxsjzw1200z.html" title="小学双减作文1200字">小学双减作文1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/1200zgzzwxr.html" title="1200字高中作文写人">1200字高中作文写人</a> <a href="https://1200zi.500zi.com/zt/1/1/rjcs1200zlw.html" title="软件测试1200字论文">软件测试1200字论文</a> <a href="https://1200zi.500zi.com/zt/1/0/fzsw1200z.html" title="风筝散文1200字">风筝散文1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/ydhzw1200z.html" title="运动会征文1200字">运动会征文1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/sz1200z.html" title="识字1200字">识字1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/xaryxcn1200z.html" title="相爱容易相处难1200字">相爱容易相处难1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/cldllw1200z.html" title="材料导论论文1200字">材料导论论文1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/sfzw1200z.html" title="书法作文1200字">书法作文1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/hjqwl1200z.html" title="寒假趣闻录1200字">寒假趣闻录1200字</a> <a href="https://1200zi.500zi.com/zt/1/1/wrmfw1200z.html" title="为人民服务1200字">为人民服务1200字</a> <a href="https://1200zi.500zi.com/zt/1/0/qtzm1200z.html" title="秋天真美1200字">秋天真美1200字</a> </div> <div class="more">展开</div> </div> </div> <div class="copyRight pc"> <p class="left">1200字范文 免责声明<span></span>© 2024 All Rights Reserved.</p> <p class="right"><a href="http://beian.miit.gov.cn/" target="_blank" rel="external nofollow">湘ICP备2024057051号</a><span></span><a href="/sitemap.html" target="_blank">网站地图</a><span></span><a href="/sitemap.xml" target="_blank">XML</a><span></span></p> </div> <div class="copyRight mobile"> <p>© 2024 All Rights Reserved.</p> <p><a href="/">1200字范文</a> 免责声明<span></span></p> </div> </div> <div id="backTop" class="none"></div> <script type="text/javascript">op('content',67824646,1);</script> </body> </html>