如何在 PHP 中读取网页 [英] How to read a web page in PHP

查看:30
本文介绍了如何在 PHP 中读取网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PHP 脚本将一些网页保存到文本文件中.

I'm trying to save some web pages to text files using PHP scripts.

如何使用 PHP 将网页加载到文件缓冲区并删除 HTML 标签?

How can I load a web page into a file buffer with PHP and remove HTML tags?

推荐答案

  • 简单的方法: fopen()file_get_contents() URL:fopen("http://google.com/", "r")
  • 聪明的方法:使用 cURL
  • 另一种聪明的方法: http_get()来自 PHP 的 http 模块
  • 困难的方法:制作一个 HTTP 请求并使用 fsockopen 发送它()stream_socket_client()
  • C 方式: 使用 sockets
  • 笨方法:通过system()调用外部工具,例如wgetcurl莉>

    • The easy way: fopen() or file_get_contents() the URL: fopen("http://google.com/", "r")
    • The smart way: Use the cURL library
    • The other smart way: http_get() from PHP's http module
    • The hard way: Craft a HTTP request and send it with fsockopen() or stream_socket_client()
    • The C way: Send a HTTP request using sockets
    • The stupid way: call an external tool such as wget or curl through system()
    • 虽然这些都不能保证在您的服务器上可用.

      None of these is guaranteed to be available on your server though.

      这篇关于如何在 PHP 中读取网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆