11
08月
2015
5. 获取 Web 页面的源代码
使用下面的函数,可以获取任意 Web 页面的 HTML 代码
1
2
3
4
5
6
7
8
9
|
function display_sourcecode( $url )
{
$lines = file( $url );
$output = "" ;
foreach ( $lines as $line_num => $line ) {
// loop thru each line and prepend line numbers
$output .= "Line #<b>{$line_num}</b> : " . htmlspecialchars( $line ) . "<br>\n" ;
}
}
|
语法:
1
2
3
4
5
|
<?php
$url = "http://blog.koonk.com" ;
$source = display_sourcecode( $url );
echo $source ;
?>
|
特殊说明,本文版权归 ning个人博客 所有带原创标签请勿转载,转载请注明出处.