php 讀取文字檔解決思路

來源:互聯網
上載者:User
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} == '<') {    if($s) {      parse_str($s, $t);      $r[] = $t;      $s = '';    }    continue;  }  $s .= ($s ? '&' : '') . $buf;}fclose($fp);print_r($r);
------解決方案--------------------
嘮叨老大出手,你就可以解帖了,應該。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.