php读取文本文件内容~

来源:百度知道 编辑:UC知道 时间:2024/05/27 11:41:35
读取一个文本文件内容如下
1 aaaa bbba ccca
2 aaaa bbbb cccb
3 aaaa bbbc cccc
3 aaaa bbbc cccc
用file+explode函数读取后,可以在页面显示出来
但是为了美观怎样才能如图所示以表格形式显示到页面?

示例代码1: 用file_get_contents 以get方式获取内容
代码如下:
<?php
$url='';
$html=file_get_contents($url);
//print_r($http_response_header);
ec($html);
printhr();
printarr($http_response_header);
printhr();
?>
  
示例代码2: 用fopen打开url, 以get方式获取内容
代码如下:
<?
$fp=fopen($url,'r');
printarr(stream_get_meta_data($fp));
printhr();
while(!feof($fp)){
$result.=fgets($fp,1024);
}
echo"url body:$result";
printhr();
fclose($fp);
?>
  
示例代码3:用file_get_contents函数,以post方式获取url
代码如下:
<?php
$data=array('foo'=>'bar');
$data=http_build_query($data);
$opts=array(
'http'=>array(
'method'=>'POST',
'header'=>"Content-type: application/x-www-form-urlencodedrn".
"Content-Length: ".strlen($data)."rn",
'content'=