IanDMac

09-05-2009, 01:29 PM

Hi all,

Please forgive if this is what you experts would call basic, but I am trying to learn and after weeks of different attempts (failures) and too many books and web sites to mention, would appreciate some pointers on creating one or more arrays from a text file, where the text file does not have a single or straight forward explode usage ability.

The file I am trying to create the arrays from has quite a bit of differing information in it, which in its fullest complete form could look like this (but can change obviously):

220900;

$::g_pDiscountBlob =

{

'VERSION' => 2,

'ONE_PRODUCT_DISCOUNT' => 0,

'ONE_ORDER_DISCOUNT' => '0',

'ONE_ORDER_DISCOUNT_SURCHAGE' => '0',

'COUPON_ON_CART' => 0,

'COUPON_ON_CHECKOUT' => 1,

'COUPON_ON_PRODUCT' => 0,

'CONSOLIDATE_MONEY_OFF' => 1,

'CONSOLIDATE_PERCENTAGE_OFF' => 0,

'CONSOLIDATE_PERCENTAGE_OFF_CHEAPEST' => 0,

'CONSOLIDATE_MONEY_OFF_EXTRA' => 0,

'CONSOLIDATE_PERCENTAGE_OFF_EXTRA' => 0,

'CONSOLIDATE_FIXED_PRICE' => 0,

'ORDER_LEVEL' => [

{

'ID' => 1,

'TYPE' => 0,

'DESCRIPTION' => 'Order Value no Code - Perc',

'REWARD_TYPE' => 1,

'BASIS' => 0,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'10000' => '-5.00%',

'20000' => '-6.00%',

'40000' => '-7.50%',

'100000' => '-12.50%',

},

'RESTRICTIONS' => {

'C_2' => 1,

},

},

{

'ID' => 4,

'TYPE' => 0,

'DESCRIPTION' => 'Order Value with Code - Perc',

'REWARD_TYPE' => 1,

'BASIS' => 2,

'REQUIRES_COUPON' => 1,

'COUPON_CODE' => '25f9e794323b453885f5181f1b624d0b',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'5000' => '-5.00%',

'10000' => '-10.00%',

'20000' => '-15.00%',

},

'RESTRICTIONS' => {

},

},

{

'ID' => 5,

'TYPE' => 0,

'DESCRIPTION' => 'Order Value no Code - Amt',

'REWARD_TYPE' => 0,

'BASIS' => 2,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'10000' => '-2500',

'50000' => '-3500',

},

'RESTRICTIONS' => {

},

},

{

'ID' => 6,

'TYPE' => 0,

'DESCRIPTION' => 'Ex Vat discount Amt',

'REWARD_TYPE' => 0,

'BASIS' => 0,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'300000' => '-40000',

},

'RESTRICTIONS' => {

},

},

{

'ID' => 7,

'TYPE' => 0,

'DESCRIPTION' => 'Restricted date perc',

'REWARD_TYPE' => 1,

'BASIS' => 0,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 1,

'USE_UNTIL_DATE' => 1,

'VALID_FROM' => '2009/09/04',

'VALID_UNTIL' => '2009/10/04',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'500000' => '-35.00%',

},

'RESTRICTIONS' => {

},

},

],

'PRODUCT_LEVEL' => [

{

'ID' => 2,

'TYPE' => 1,

'DESCRIPTION' => '3 for the price of 2',

'REWARD_TYPE' => 2,

'BASIS' => 3,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => 1,

'REWARDS' => {

'TRIGGER' => 3,

'USE_GROUP' => 0,

'MONEY_OFF' => 0,

'PERCENTAGE_OFF' => '100.00%',

'PRODUCT_GROUP' => -1,

'PRODUCT_REF' => '',

},

'RESTRICTIONS' => {

},

},

],

'PRODUCT_GROUPS' =>

{

'1' => [

0,

'Books',

''

],

}

};

return($::SUCCESS);

The first array, I would need to create is based on this section:

'VERSION' => 2,

'ONE_PRODUCT_DISCOUNT' => 0,

'ONE_ORDER_DISCOUNT' => '0',

'ONE_ORDER_DISCOUNT_SURCHAGE' => '0',

'COUPON_ON_CART' => 0,

'COUPON_ON_CHECKOUT' => 1,

'COUPON_ON_PRODUCT' => 0,

'CONSOLIDATE_MONEY_OFF' => 1,

'CONSOLIDATE_PERCENTAGE_OFF' => 0,

'CONSOLIDATE_PERCENTAGE_OFF_CHEAPEST' => 0,

'CONSOLIDATE_MONEY_OFF_EXTRA' => 0,

'CONSOLIDATE_PERCENTAGE_OFF_EXTRA' => 0,

'CONSOLIDATE_FIXED_PRICE' => 0,

'ORDER_LEVEL' => [

But, then would need to create unique arrays for sections like this:

{

'ID' => 1,

'TYPE' => 0,

'DESCRIPTION' => 'Order Value no Code - Perc',

'REWARD_TYPE' => 1,

'BASIS' => 0,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'10000' => '-5.00%',

'20000' => '-6.00%',

'40000' => '-7.50%',

'100000' => '-12.50%',

},

'RESTRICTIONS' => {

'C_2' => 1,

},

},

Where the array is created based on the Type => x , so all '0' into a multi array, and all '1' into a multi array and so on.

My problem that I keep hitting is that every time I read through the lines, my different attempts at Start TYPE 0 create arrays and then stop at end, and explode key => populates nothing, although I know the file is being read ok as I can echo it all out ok line by line.

Any pointers would be appreciated as not expecting the solution to it all.

Thanks for any assistance in advance.

Ian

Please forgive if this is what you experts would call basic, but I am trying to learn and after weeks of different attempts (failures) and too many books and web sites to mention, would appreciate some pointers on creating one or more arrays from a text file, where the text file does not have a single or straight forward explode usage ability.

The file I am trying to create the arrays from has quite a bit of differing information in it, which in its fullest complete form could look like this (but can change obviously):

220900;

$::g_pDiscountBlob =

{

'VERSION' => 2,

'ONE_PRODUCT_DISCOUNT' => 0,

'ONE_ORDER_DISCOUNT' => '0',

'ONE_ORDER_DISCOUNT_SURCHAGE' => '0',

'COUPON_ON_CART' => 0,

'COUPON_ON_CHECKOUT' => 1,

'COUPON_ON_PRODUCT' => 0,

'CONSOLIDATE_MONEY_OFF' => 1,

'CONSOLIDATE_PERCENTAGE_OFF' => 0,

'CONSOLIDATE_PERCENTAGE_OFF_CHEAPEST' => 0,

'CONSOLIDATE_MONEY_OFF_EXTRA' => 0,

'CONSOLIDATE_PERCENTAGE_OFF_EXTRA' => 0,

'CONSOLIDATE_FIXED_PRICE' => 0,

'ORDER_LEVEL' => [

{

'ID' => 1,

'TYPE' => 0,

'DESCRIPTION' => 'Order Value no Code - Perc',

'REWARD_TYPE' => 1,

'BASIS' => 0,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'10000' => '-5.00%',

'20000' => '-6.00%',

'40000' => '-7.50%',

'100000' => '-12.50%',

},

'RESTRICTIONS' => {

'C_2' => 1,

},

},

{

'ID' => 4,

'TYPE' => 0,

'DESCRIPTION' => 'Order Value with Code - Perc',

'REWARD_TYPE' => 1,

'BASIS' => 2,

'REQUIRES_COUPON' => 1,

'COUPON_CODE' => '25f9e794323b453885f5181f1b624d0b',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'5000' => '-5.00%',

'10000' => '-10.00%',

'20000' => '-15.00%',

},

'RESTRICTIONS' => {

},

},

{

'ID' => 5,

'TYPE' => 0,

'DESCRIPTION' => 'Order Value no Code - Amt',

'REWARD_TYPE' => 0,

'BASIS' => 2,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'10000' => '-2500',

'50000' => '-3500',

},

'RESTRICTIONS' => {

},

},

{

'ID' => 6,

'TYPE' => 0,

'DESCRIPTION' => 'Ex Vat discount Amt',

'REWARD_TYPE' => 0,

'BASIS' => 0,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'300000' => '-40000',

},

'RESTRICTIONS' => {

},

},

{

'ID' => 7,

'TYPE' => 0,

'DESCRIPTION' => 'Restricted date perc',

'REWARD_TYPE' => 1,

'BASIS' => 0,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 1,

'USE_UNTIL_DATE' => 1,

'VALID_FROM' => '2009/09/04',

'VALID_UNTIL' => '2009/10/04',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'500000' => '-35.00%',

},

'RESTRICTIONS' => {

},

},

],

'PRODUCT_LEVEL' => [

{

'ID' => 2,

'TYPE' => 1,

'DESCRIPTION' => '3 for the price of 2',

'REWARD_TYPE' => 2,

'BASIS' => 3,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => 1,

'REWARDS' => {

'TRIGGER' => 3,

'USE_GROUP' => 0,

'MONEY_OFF' => 0,

'PERCENTAGE_OFF' => '100.00%',

'PRODUCT_GROUP' => -1,

'PRODUCT_REF' => '',

},

'RESTRICTIONS' => {

},

},

],

'PRODUCT_GROUPS' =>

{

'1' => [

0,

'Books',

''

],

}

};

return($::SUCCESS);

The first array, I would need to create is based on this section:

'VERSION' => 2,

'ONE_PRODUCT_DISCOUNT' => 0,

'ONE_ORDER_DISCOUNT' => '0',

'ONE_ORDER_DISCOUNT_SURCHAGE' => '0',

'COUPON_ON_CART' => 0,

'COUPON_ON_CHECKOUT' => 1,

'COUPON_ON_PRODUCT' => 0,

'CONSOLIDATE_MONEY_OFF' => 1,

'CONSOLIDATE_PERCENTAGE_OFF' => 0,

'CONSOLIDATE_PERCENTAGE_OFF_CHEAPEST' => 0,

'CONSOLIDATE_MONEY_OFF_EXTRA' => 0,

'CONSOLIDATE_PERCENTAGE_OFF_EXTRA' => 0,

'CONSOLIDATE_FIXED_PRICE' => 0,

'ORDER_LEVEL' => [

But, then would need to create unique arrays for sections like this:

{

'ID' => 1,

'TYPE' => 0,

'DESCRIPTION' => 'Order Value no Code - Perc',

'REWARD_TYPE' => 1,

'BASIS' => 0,

'REQUIRES_COUPON' => 0,

'COUPON_CODE' => 'd41d8cd98f00b204e9800998ecf8427e',

'USE_FROM_DATE' => 0,

'USE_UNTIL_DATE' => 0,

'VALID_FROM' => '',

'VALID_UNTIL' => '',

'RESTRICTED_TO_PAYMENT' => 0,

'RESTRICTED_TO_CUSTOMER' => 0,

'CART_DESC' => '',

'ONE_PER_ORDER' => 0,

'GROUPID' => -1,

'REWARDS' => {

'10000' => '-5.00%',

'20000' => '-6.00%',

'40000' => '-7.50%',

'100000' => '-12.50%',

},

'RESTRICTIONS' => {

'C_2' => 1,

},

},

Where the array is created based on the Type => x , so all '0' into a multi array, and all '1' into a multi array and so on.

My problem that I keep hitting is that every time I read through the lines, my different attempts at Start TYPE 0 create arrays and then stop at end, and explode key => populates nothing, although I know the file is being read ok as I can echo it all out ok line by line.

Any pointers would be appreciated as not expecting the solution to it all.

Thanks for any assistance in advance.

Ian