How to solve string truncation

Source: Internet
Author: User
Tags preg
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 
    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.