如何在php中获取html的一部分 [英] how to get some part of a html body in php

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

问题描述

我只想得到一些HTML主体的一些内容,并且我使用PHP和c URL(例如前10行)。通过获取一些部分,我的意思是我不想下载整个文件并获得它的一些部分。



有没有什么方法可以获得HTML的某些部分来自服务器本身的文件?通过在curl或PHP中进行一些设置。如果服务器支持它,您可以发出一个范围请求。

>

在您的HTTP请求标题中添加:

  curl_setopt($ ch,CURLOPT_HTTPHEADER ,数组(
'范围:0-1500',
));

...获得前1500个字节,这可能是也可能不是前10行,具体取决于

这个问题(除了服务器可能缺乏支持)之外,你需要知道你想要的文档中的哪些字节和那么您必须从部分HTML中提取数据,而不是完整的HTML文档。


I want to get only some lines of an HTML body and I am using PHP with c URL (e.g. first 10 lines). By getting some part I mean that I don't want to download the whole file and get some parts of it.

Is there any way to get only some parts of HTML files from the server itself? by doing some setting in curl or PHP.

解决方案

If the server supports it, you can make a range request.

Add, to your HTTP request headers:

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Range: 0-1500',
    ));

… to get the first 1500 bytes, which may or may not be the first ten lines, depending on how long the lines are.

The problem with this (aside from possible lack of support by the server) is that you need to know which bytes in the document you want and then you have to extract the data from a partial HTML instead of a complete HTML document.

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

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