String truncation bri = bridge0if1 = wanif2 = lanif3 = vlanmac = 00: 11: 22: 1d: 2d: 3dip = 192.168.100.1netmask = 255.255.255.0arp = arpstate = stopbri = bridge1 string interception
Bri = bridge0 if1 = wan if2 = lan if3 = vlan mac = 00: 11: 22: 1d: 2d: 3d ip = 192.168.100.1 netmask = 255.255.255.0 arp = arp state = stop
Bri = bridge1 if1 = wan mac = 00: 01: 2B: 4C: 6D: 9F ip = 192.168.1.125 netmask = 255.255.255.0 state = stop
This is my saved configuration file
However, if headers are multiple choices, and the number of headers is not fixed. a maximum of eight are available. I want to retrieve the value of if.
That is
Bridge0: wan lan vlan
Bridge1: wan
This data is converted to an array
PHP code
Array( [0] => Array ( [bri] => bridge0 [if1] => wan [if2] => lan [if3] => vlan [mac] => 00:11:22:1d:2d:3d [ip] => 192.168.100.1 [netmask] => 255.255.255.0 [arp] => arp [state] => stop ) [1] => Array ( [bri] => bridge1 [if1] => wan [mac] => 00:01:2B:4C:6D:9F [ip] => 192.168.1.125 [netmask] => 255.255.255.0 [state] => stop ))
Is there any good way?
After converting to an array, judge based on the key value
------ Solution --------------------
PHP code
$ S = "bri = bridge0 if1 = wan if2 = lan if3 = vlan mac = 00: 11: 22: 1d: 2d: 3d ip = 192.168.100.1 netmask = 255.255.255.0 arp = arp state = stop "; parse_str (strtr ($ s,'', '&'), $ a); print_r ($ );
------ Solution --------------------
Isn't it the key starting with if.
PHP code
[User:root Time:17:19:16 Path:/home/liangdong/php]$ php preg.php bridge0: wan lan vlanbridge1: wan[User:root Time:17:19:16 Path:/home/liangdong/php]$ cat preg.php