Discuz教程网

PHP获取url的函数代码

[复制链接]
authicon dly 发表于 2011-9-5 19:36:05 | 显示全部楼层 |阅读模式
代码如下:

  1. function geturl($url)
  2. {
  3. $ch = curl_init();
  4. $timeout = 5;
  5. curl_setopt($ch, CURLOPT_URL, $url);
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  8. //在需要用户检测的网页里需要增加下面两行
  9. //curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  10. //curl_setopt($ch, CURLOPT_USERPWD, US_NAME.”:”.US_PWD);
  11. $contents = curl_exec($ch);
  12. curl_close($ch);
  13. $contents = str_replace("document.write('","",$contents);
  14. $contents = str_replace("');","",$contents);
  15. $contents = str_replace("\\n","",$contents);
  16. $contents = str_replace("\","",$contents);
  17. echo $contents;
  18. }
复制代码







上一篇:10条PHP高级技巧[修正版]
下一篇:给初学者的30条PHP最佳实践(荒野无灯)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 20:08

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表