file
(PHP 3, PHP 4 )
file -- 把整个文件读入一个数组中
说明:file ( string filename [, int use_include_path [, resource context]])
和 readfile() 一样,只除了 file() 将文件作为一个数组返回。数组中的每个单元都是文件中相应的一行,包括换行符在内。如果失败 file() 返回 FALSE。
<?php
// 将一个文件读入数组。本例中通过 HTTP 从 URL 中取得 HTML 源文件。
$lines = file ('http://www.example.com/');
// 在数组中循环,显示 html 的源文件并加上行号。
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}
// 另一个例子将 web 页面读入字符串。参见 file_get_contents()。
$html = implode ('', file ('http://www.example.com/'));
?>

提示: 如果“fopen wrappers”已经被激活,则您在使用该函数的时候,可以把 URL 作为文件名来使用。
注: 返回的数组中每一行都包括了行结束符,因此如果不需要行结束符时还需要使用 trim() 函数。
注: 如果碰到 PHP 在读取文件时不能识别 Macintosh 文件格式,可以激活 auto_detect_line_endings 的运行时配置选项。
注: 从 PHP 4.3.0 开始可以用 file_get_contents() 来将文件读入到一个字符串返回。
从 PHP 4.3.0 开始 file() 可以安全用于二进制文件。
注: Context 支持是 PHP 5.0.0 新加的。

array
Line #0 : <!doctype html> 
Line #1 : <html> 
Line #2 : <head> 
Line #3 : <title>Example Domain</title> 
Line #4 : 
Line #5 : <meta charset="utf-8" /> 
Line #6 : <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
Line #7 : <meta name="viewport" content="width=device-width, initial-scale=1" /> 
Line #8 : <style type="text/css"> 
Line #9 : body { 
Line #10 :  
Line #11 : margin: 0; 
Line #12 : padding: 0; 
Line #13 : font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; 
Line #14 : 
Line #15 : } 
Line #16 : div { 
Line #17 : width: 600px; 
Line #18 : margin: 5em auto; 
Line #19 : padding: 50px; 
Line #20 :  
Line #21 : border-radius: 1em; 
Line #22 : } 
Line #23 : a:link, a:visited { 
Line #24 : color: #38488f; 
Line #25 : text-decoration: none; 
Line #26 : } 
Line #27 : @media (max-width: 700px) { 
Line #28 : body { 
Line #29 :  
Line #30 : } 
Line #31 : div { 
Line #32 : width: auto; 
Line #33 : margin: 0 auto; 
Line #34 : border-radius: 0; 
Line #35 : padding: 1em; 
Line #36 : } 
Line #37 : } 
Line #38 : </style> 
Line #39 : </head> 
Line #40 : 
Line #41 : <body> 
Line #42 : <div> 
Line #43 : <h1>Example Domain</h1> 
Line #44 : <p>This domain is established to be used for illustrative examples in documents. You may use this 
Line #45 : domain in examples without prior coordination or asking for permission.</p> 
Line #46 : <p><a href="http://www.iana.org/domains/example">More information...</a></p> 
Line #47 : </div> 
Line #48 : </body> 
Line #49 : </html>

php获取网页源码分行显示的更多相关文章

  1. C语言之socket获取网页源码

    写爬虫也许你用的是python,类似urlopen(url).read()即可获得普通的网页的源码,或者用的java的网络库加上流操作,或者其他高级语言.但你有没有想过使用C语言来实现呢?我曾经以为用 ...

  2. QT:轻松获取网页源码

    获取网页源码的小例子,代码很简单,就不多作解释了. 不过一定要注意网页的编码问题,否则会出现乱码的!!! #include <QtCore> #include <QtNetwork& ...

  3. Python爬虫学习之获取网页源码

    偶然的机会,在知乎上看到一个有关爬虫的话题<利用爬虫技术能做到哪些很酷很有趣很有用的事情?>,因为强烈的好奇心和觉得会写爬虫是一件高大上的事情,所以就对爬虫产生了兴趣. 关于网络爬虫的定义 ...

  4. vc++获取网页源码

    1. 获取网页源码的步骤: com组件的初始化 创建WinHttpRequest对象 创建并实例化WinHttpRequest组件 调用Open方法打开连接 调用Send方法发送请求 使用Respon ...

  5. vc++获取网页源码之使用import+接口方式

    1.使用IWinHttpRequest获取网页源码 首先要创建基于对话框的mfc应用程序 2.import+接口方式 首先导入winhttp.dll,使用IWinHttpRequest接口 #impo ...

  6. 高效获取网页源码COM

    目前获取网页源码有几种方法: 1.WebClient下载页面2.HttpWebRequest发请求获取3.com组件xmlhttp获取 三者比较:WebClient代码最少,效率最慢:xmlhttp代 ...

  7. Python3 Selenium WebDriver网页的前进、后退、刷新、最大化、获取窗口位置、设置窗口大小、获取页面title、获取网页源码、获取Url等基本操作

    Python3 Selenium WebDriver网页的前进.后退.刷新.最大化.获取窗口位置.设置窗口大小.获取页面title.获取网页源码.获取Url等基本操作 通过selenium webdr ...

  8. Python3.x获取网页源码

    Python3.x获取网页源码 1,获取网页的头部信息以确定网页的编码方式: import urllib.request res = urllib.request.urlopen('http://ww ...

  9. c# HttpClient获取网页源码

    #region 获取网页源码 public static string HttpClientGetHtmls(string url) { try { var client = new HttpClie ...

随机推荐

  1. php wordwrap()函数 语法

    php wordwrap()函数 语法 wordwrap()函数怎么用? wordwrap()函数表示按照指定长度对字符串进行折行处理,语法是wordwrap(string,width,break,c ...

  2. UNP学习第九章 基本名字与地址转换

    之前都用数值地址来表示主机(206.6.226.33),用数值端口号来标识服务器. 然而,我们应该使用名字而不是数值:名字比较容易记,数值地址可以改变但名字保持不变. 随着往IPv6上转移,数值地址变 ...

  3. 存储-docker数据共享(13)

    容器与 host 共享数据 我们有两种类型的 data volume,它们均可实现在容器与 host 之间共享数据,但方式有所区别. 对于 bind mount 是非常明确的:直接将要共享的目录 mo ...

  4. echarts 柱状图 X(Y)轴数据过多时,滑动以及内置缩放的问题

    前言:在开发中碰到的情况(菜鸟出门).           在使用echarts 图表的时候发现要展示的数据过多,但是系统留的展示框太小,造成数据都挤压在一块(不好看而且新感觉很不专业).       ...

  5. WebGPU学习(九):学习“fractalCube”示例

    大家好,本文学习Chrome->webgpu-samplers->fractalCube示例. 上一篇博文: WebGPU学习(八):学习"texturedCube"示 ...

  6. Win10+CentOS7双系统引导修复

    在有Win10的系统下安装了CentOS7后,CentOS7的引导并不会像CentOS6一样自动加载入Win10驱动.难道是grub2不能引导Win驱动?查了一下资料原来是CentOS不能识别Win1 ...

  7. 数据访问层的超级基类AbstractBaseDAL

    using System; using System.Collections; using System.Data; using System.Data.Common; using System.Co ...

  8. C/s模式&&B/S模式

    C/s模式:是客户端/服务器(Client/Server)模式,主要指的是传统的桌面级的应用程序.比如我们经常用的信息管理系统. C/S 客户端/服务器 例如QQ,网络游戏,需要下载客户端才能访问服务 ...

  9. 力扣算法——139WordBreak【M】

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine ...

  10. 02、python的基础-->占位符、while...else...、逻辑运算符

    1.%s.%d格式化输出程序(%占位符,s字符串,d数字) name = input('请输入姓名:') age = input('请输入年龄:') job = input('请输入工作:') hob ...