php获取网页源码分行显示

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> 

转载于:https://www.cnblogs.com/dsli/p/7420516.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值