Re: [請益] 字串問題

看板PHP作者 (Powered by Zend Engine2)時間18年前 (2007/04/30 02:04), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串4/4 (看更多)
※ 引述《kalasiya (呼呼)》之銘言: : 假設我有一個檔 : 譬如內容是這樣: : <a<a>a<<a><a>a>a> : 要顯示出 : <a<a>a<<a><a>a>a> : <a> : <<a><a>a> : <a> : <a> : 將每個括號和其內的子括號的內容秀出來 : php有沒有比較好的作法? <?php function foo ($str) { echo "$str\n"; $str = substr ($str, 1, -1); while (strpos ($str, "<")!==false && strpos ($str, ">")!==false) { $str = substr ($str, strpos ($str, "<")); $count1=0; $count2=0; for ($i=0; $i<strlen($str); $i++) { if (substr($str,$i,1) == "<") $count1++; elseif (substr($str,$i,1) == ">") $count2++; if ($count1==$count2) break; } foo (substr($str, 0, $i+1)); $str = substr ($str, $i+1); } } foo ("<a<a>a<<a><a>a>a>"); ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.245.58 ※ 編輯: PHP5 來自: 140.112.245.58 (04/30 02:05)

04/30 13:53, , 1F
感謝~~不過秀出來的結果怪怪的
04/30 13:53, 1F
文章代碼(AID): #16DDv77a (PHP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
1
3
完整討論串 (本文為第 4 之 4 篇):
1
1
1
3
文章代碼(AID): #16DDv77a (PHP)