0

I have this string saved in $metaV:

{"feedName":"Paypal Test","paypalEmail":"managercvtech@gmail.com","mode":"test","transactionType":"subscription","recurringAmount":"form_total","billingCycle_length":"1","billingCycle_unit":"day","recurringTimes":"0","recurringRetry":"0","trial_enabled":"1","trial_product":"73","trial_amount":"","trialPeriod_length":"1","trialPeriod_unit":"month","billingInformation_firstName":"4","billingInformation_lastName":"27","billingInformation_email":"5","billingInformation_address":"","billingInformation_address2":"","billingInformation_city":"","billingInformation_state":"","billingInformation_zip":"34","billingInformation_country":"","pageStyle":"","continueText":"","cancelUrl":"","disableShipping":"0","disableNote":"0","delayNotification":"0","selectedNotifications":"","feed_condition_conditional_logic":"0","feed_condition_conditional_logic_object":{"conditionalLogic":{"actionType":"show","logicType":"all","rules":[{"fieldId":"73","operator":"is","value":"1 month"}]}},"type":"subscription","recurring_amount_field":"form_total","update_user_action":"","delay_registration":"","update_site_action":""}

I want to replace this part of the string:

"trial_enabled":"0"

I tried to use str_replace() for this:

str_replace('\"trial_enabled\":\"1\"', '\"trial_enabled\":\"0\"',$metaV);
Rizier123
  • 58,877
  • 16
  • 101
  • 156
akash ujjwal
  • 174
  • 2
  • 14
  • 2
    What you have here is a JSON string. See: http://stackoverflow.com/q/29308898/3933332 how you can access this data and also get it into an array. This way it's way easier to modify the information. Right now you are trying to solve the problem the wrong way. – Rizier123 Mar 15 '16 at 18:05
  • @Rizier123 Oh, yes I'am doing it in wrong way. Thanks for your suggestion. – akash ujjwal Mar 15 '16 at 18:43

1 Answers1

1

You could use json_decode and json_encode to transform your string into an array and the way back.

$data = json_decode($metaV, true);
$data['trial_enabled'] = "1";
$metaV = json_encode($data);
Philipp
  • 15,377
  • 4
  • 35
  • 52
  • Thanks man!! it works!!...but I tried it as $metaV = explode(',', $meta); $metaV[9]='"trial_enabled":"0"'; $metaV = implode(',', $metaV); But your solution is work like charm. Thanks again. – akash ujjwal Mar 15 '16 at 18:42