3

I have an array string like this :

 Array
(
    [TRANSACTION_ID] => SFBT-U1005141804-18DZW
    [TRANSACTION_REFERENCE] => KRZTV
    [TRANSACTION_TYPE] => sale
    [TRANSACTION_STATUS_CODE] => SA
    [MERCHANT] => safebytes
    [AFFILIATE] =>
    [TRANSACTION_DATE] => 2014-05-10 18:04:51
    [CUSTOMER_AMOUNT] => 39.90
    [CUSTOMER_CURRENCY] => USD
    [CUSTOMER_NAME] => Robin Jennings
    [CUSTOMER_EMAIL] => [email protected]
    [CUSTOMER_COUNTRY] => US
    [CUSTOMER_ADDRESS] =>
    [CUSTOMER_CITY] =>
    [CUSTOMER_REGION] => NJ
    [CUSTOMER_ZIP_POSTAL] => 07067
    [CUSTOMER_LANGUAGE] => EN
    [CUSTOMER_PHONE_NUMBER] =>
    [CUSTOMER_IP] => 96.225.124.15
    [CUSTOMER_IP_ADDRESS] => 96.225.124.15
    [PAYMENT_METHOD] => PAYPAL
    [SKU] => totalsystemcare/1pk1yr
    [ORDER_STATUS] => SUCCESS
    [NOTES] => NONE
    [PAYOUT_CURRENCY] => USD
    [PAYOUT_AMOUNT] => 36.13
    [TAXES_AMOUNT] => 0.00
    [VOID] => N
    [QUERY] => sku%5B0%5D%3Dtotalsystemcare%2F1pk1yr%26ec%3D2404%26os%3DWindows+7%26osb%3D64bit%26pr%3DIntel%28R%29+Core%28TM%29+i3+CPU+++++++M+380++%40+2.53GHz%26mb%3DDell+Inc.+0THYJV%26vc%3DIntel%28R%29+HD+Graphics%26ram%3D3.80+GB%26hd%3D465.76+GB%26isp%3D%26UID%3DE294A80C-28B1-444B-935A-2D58F8A034D2%26det_country%3DUnited+States%26cou
    [EVENT_ID] => 1
    [PROCESSOR] => SafeCart
    [BILL_AMOUNT] => 39.9
    [ITEMS] => [{"SKU":"totalsystemcare\/1pk1yr","PRICE":"39.90000","QUANTITY":1,"PAYOUT":"36.12695","TAX":0,"RECURRING":true}]
)

This string is written in the txt file . How I can parse it in the php array. I have already get it from file but I can't parse it into array.

can anyone help me ?

2
  • So you just want to turn the php array, written as a string imported from a file, back into a php array? Isn't your work laid out for you, especially if you know exactly how each item is formatted etc? I honestly have no formal experience with php but it seems like between php.net/manual/en/language.types.array.php and us2.php.net/preg_match you should be able to easily tackle your problem. Commented May 20, 2014 at 6:38
  • 1
    If you have control of the data at the point of export then you should be exporting it in a format that can easily be re-imported back into PHP. You could serialize() or json_encode() it for starters, and then use unserialize() or json_decode() to import it back in. Commented May 20, 2014 at 6:58

1 Answer 1

5

Your can use a var_export function for save PHP variables to file.

For example:

$data = array('Foo', 'Bar');
file_put_contents('filename.txt', '<?php return ' . var_export($data, true) . ';');

// And get this content
$data = include 'filename.txt';
Sign up to request clarification or add additional context in comments.

1 Comment

@ZhukV file_put_contents('vol/filename.txt', '<?php return ' . var_export($data, true).';'); use ; in the end otherwise it will return error unexpected $end in filename.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.