Home  >  Article  >  Backend Development  >  php 读取文本文件解决思路

php 读取文本文件解决思路

WBOY
WBOYOriginal
2016-06-13 10:07:29977browse

php 读取文本文件
用fopen打开后,一行行读,[email protected],当有(标签开始时开始读)读里面的三个属性,再遇下一个标签后,就把前三个作为数组拿出来,也就是把每个标签中间的读完是三个元素的数组拿出来处理,读完为止.
这样的方法怎么写呀?
#vision1.1
@fileid=0010

name=xx
id=0
orth=zzz

name=xx
id=801
orth=/btf/sub.txt


name=xx
id=101
orth=/bbs/test.txt



------解决方案--------------------
[email protected],从开始:
当找到时,用变量一次性记录下 $firstNode="";处理下使$firstNode="";
然后一行行处理判断当前行如果=$firstNode,
则读到此为止...
此是间的内容全部取出.

至于....>正则处理..
------解决方案--------------------

PHP code
$fn = 'data2.txt';$fp = fopen($fn, 'r');$s = '';while($buf = fgets($fp)) {  if(in_array($buf{0}, array('#', '@'))) continue;  if($buf{0} == '<font color="#e78608">------解决方案--------------------</font><br>唠叨老大出手,你就可以解帖了,应该。<div class="clear">
                 
              
              
        
            </div>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn