【发布时间】:2012-09-11 13:13:44
【问题描述】:
我想像 C++ 那样读取文本文件
这是文本文件中的示例
(item(name 256) (desc 520)(Index 1)(Image "Wea001") (specialty (aspeed 700)))
(item (name 257) (desc 520) (Index 2) (Image "Wea002")(specialty(Attack 16 24)))
我想要这样的输出
name : 256
Desc : 520
Index : 1
Image : Wea001
Specialty > aspeed : 700
Name : 257
Desc : 520
Index : 2
Image : Wea002
Speciality > Attack : 16 24
这可能吗?
我试过了:
preg_match_all('/name\s+(.*?)\)\+\(desc\s+(.*?)\)\+\(Index\s+(.*?)\)/', $text, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
list (, $name, $desc, $index) = $match;
echo 'name : '.$name.' <br> Desc : '.$desc.'<br> Index : '.$index.'';
}
但它没有给我想要的正确输出。
谢谢
【问题讨论】:
-
天哪,这是一种令人讨厌的格式。它来自哪里?能改吗?
-
Lisp 攻击!这么多括号!
标签: php