有一個文字檔 abc.txt
內容如下
conf
link-group %left2% access
dot1q pvc %left3% profile to-dot1p
description %sub%
qos policy policing %qospolicy%
bind bypss
end
conf
link-group %right2% access
dot1q pvc %right3% profile to-dot1p
description %sub%
qos policy policing %qospolicy%
bind bypss
end
conf
xc-group default
xc lg %left2% vlan-id %left3% to lg %right2% vlan-id %right3%
end
我希望用 preg_match 或是 preg_match_all
抓出 %% 裡面所有的值
共有12個
如果只是單純的
$a = file_get_contents('abc.txt');
preg_match_all('/%.*%/',$a,$matches);
print_r($matches);
結果會是
Array
(
[0] => Array
(
[0] => %left2%
[1] => %left3%
[2] => %sub%
[3] => %qospolicy%
[4] => %right2%
[5] => %right3%
[6] => %sub%
[7] => %qospolicy%
[8] => %left2% vlan-id %left3% to lg %right2% vlan-id %right3%
)
)
那一行有 4個 %% 的無法個別抓出
請大家指導
謝謝