将html文件读入字符串 [英] reading an html file into a string

查看:87
本文介绍了将html文件读入字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的本地服务器读取一个html文件为一个字符串,我是<​​br />
使用以下代码:


$ attfile = $ attachment [$ i]; //创建文件名

$ file_name = basename($ attfile);

$ lines = file($ attfile); //将文件放入数组


foreach($ line as $ line_num => $ line){//连接每一行

$ fcontent。= $线路;

}


这应该只是将文件作为一个数组加载然后通过每一行并添加

它到$ fcontent变量的结尾。这样做但是在较大的文件上

(4000多行html)它会在接近结尾的行中停止。

基本上它错过了大约10- html文件末尾的15行


我已经增加了文件的大小,它似乎总是停在

结尾附近,但是完成之前退出的行。所以我猜这不是一些

随机字符组合,可以将其删除或达到某种缓冲区

限制。


有没有人有任何想法或知道一个简单的脚本,它将获取一个html文件的

内容并将其放入一个字符串(而不是一个数组)。我正在使用

4.2.2而没有升级的机会所以我不能使用file_get_contents。


谢谢

Alex

解决方案

attfile =


附件


< BLOCKQUOTE> I]; //创建文件名


I''m trying to read an html file from my local server into a string, I''m
using the following code:

$attfile = $attachment[$i]; //create filenames
$file_name = basename ($attfile);
$lines = file($attfile); //get file into array

foreach ($lines as $line_num => $line) { //concatenate each line
$fcontent.= $line;
}

This should just load the file as an array then go through each line and add
it to the end of the $fcontent variable. It does this but on larger files
(4000+ lines of html) it stops part way through a line ver close to the end.
Basically it misses off about 10-15 lines at the end of the html file

I''ve increased the size of the file and it always seems to stop near the
end, but the line where it quit before is finished. So I guess it''s not some
random character combination excaping it or reaching some kind of buffer
limit.

Does anyone have any ideas or know a simple script that will grab the
contents of an html file and put it into a string (not an array). I''m using
4.2.2 with no chance of upgrading so I can''t use file_get_contents.

Thanks
Alex

解决方案

attfile =


attachment


i]; //create filenames


这篇关于将html文件读入字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆