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

php 读取文本文件解决思路

WBOY
Release: 2016-06-13 13:48:05
Original
804 people have browsed it

php 读取文本文件
用fopen打开后,一行行读,#和@开头的过滤掉,当有(标签开始时开始读)读里面的三个属性,再遇下一个标签后,就把前三个作为数组拿出来,也就是把每个标签中间的读完是三个元素的数组拿出来处理,读完为止.
这样的方法怎么写呀?
#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



------解决方案--------------------
前两行的#和@过滤好处理,从开始:
当找到时,用变量一次性记录下 $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>
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template