如何过滤MySQL单元格中的数据

时间:2016-10-16 14:03:45

标签: php

我在MySQL数据库的单元格中有以下数据:

mc_gross = 213.94 invoice = 8 protection_eligibility = Eligible address_status = confirmed item_number1 = 1379444095 payer_id = UIHUI43SOMEID tax = 0.00 address_street = some address payment_date = 11:57:10 Sep 17, 2013 PDT payment_status = Completed charset = windows-1252 address_zip = 77777 mc_shipping = 0.00 mc_handling = 0.00 first_name = John mc_fee = 5.01 address_country_code = US address_name = John Doe notify_version = 3.7 custom = 8 payer_status = verified business = support@website.net address_country = United States num_cart_items = 1 mc_handling1 = 0.00 address_city = some city verify_sign = 1@3fsome*key payer_email = guy@website.com mc_shipping1 = 0.00 tax1 = 0.00 txn_id = 1RFSOMEID3S payment_type = instant last_name = Doe address_state = AZ item_name1 = Order Number: 1379444095 receiver_email = guy2@website.com payment_fee = 5.01 quantity1 = 1 receiver_id = GAGESOMEID tx ...

如何在等号后过滤信息并仅提取数据?

3 个答案:

答案 0 :(得分:1)

从数据库中检索数据后,您可以使用正则表达式执行此操作,例如preg_mathchpreg_match_all('/\s[^=]+="[^"]+"/', $string, $matches);

答案 1 :(得分:1)

有几个相同的迹象。您可以使用正则表达式匹配来收集等号之后/之间的任何或所有部分。

答案 2 :(得分:1)

我相信您可以使用正则表达式将其拆分为键值对,如下所示:

preg_match_all('/[a-zA-Z_]+\s+=+\s+[^\s]+/', $a, $matches);

因此基于提供的字符串$ matches将包含:

Array
(
    [0] => Array
        (
            [0] => mc_gross = 213.94
            [1] => invoice = 8
            [2] => protection_eligibility = Eligible
            [3] => address_status = confirmed
            [4] => payer_id = UIHUI43SOMEID
            [5] => tax = 0.00
            [6] => address_street = some
            [7] => payment_date = 11:57:10
            [8] => payment_status = Completed
            [9] => charset = windows-1252
            [10] => address_zip = 77777
            [11] => mc_shipping = 0.00
            [12] => mc_handling = 0.00
            [13] => first_name = John
            [14] => mc_fee = 5.01
            [15] => address_country_code = US
            [16] => address_name = John
            [17] => notify_version = 3.7
            [18] => custom = 8
            [19] => payer_status = verified
            [20] => business = support@website.net
            [21] => address_country = United
            [22] => num_cart_items = 1
            [23] => address_city = some
            [24] => verify_sign = 1@3fsome*key
            [25] => payer_email = guy@website.com
            [26] => txn_id = 1RFSOMEID3S
            [27] => payment_type = instant
            [28] => last_name = Doe
            [29] => address_state = AZ
            [30] => receiver_email = guy2@website.com
            [31] => payment_fee = 5.01
            [32] => receiver_id = GAGESOMEID
        )
)