php 如何把整个页面包含在一个字符串中

来源:百度知道 编辑:UC知道 时间:2024/09/27 11:30:44

$string = file_get_contents($url);
将整个页面作为一个字符串返回

用 file(url)或者fopen(url) 函数把一个页面在运行时读取出来,就自然到一个字串变量里了。 做抓取机器人一般都用这种方式 。

<?php
$str="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN''http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312' /><title>无标题文档</title></head><body><table width='100%' cellspacing='1'>
<tr bgcolor='#FF0000'>
<td><span class='STYLE2'>1</span></td>
<td><span class='STYLE2'>2</span></td>
<td&g