替换包含双qoutes和冒号的字符串

时间:2016-03-15 18:03:29

标签: php json string

我将此字符串保存在$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":""}

我想替换字符串的这一部分:

"trial_enabled":"0"

我尝试使用str_replace()

str_replace('\"trial_enabled\":\"1\"', '\"trial_enabled\":\"0\"',$metaV);

1 个答案:

答案 0 :(得分:1)

您可以使用json_decodejson_encode将字符串转换为数组并返回。

$data = json_decode($metaV, true);
$data['trial_enabled'] = "1";
$metaV = json_encode($data);