Danryl Tigol Carpio
Danryl Tigol Carpio

Reputation: 111

How to remove unwanted characters in JSON String array format PHP

How can I clean Dirty JSON String format ?

For Example from this String

{"AS_applicant_Data__c":"{\\\"Full Name\u00a0\\\":\\\"asdffas\\\"}"}

to this format

{"AS_applicant_Data__c":"{"Full Name":"asdffas"}"}

Upvotes: 1

Views: 3164

Answers (1)

Rajdeep Paul
Rajdeep Paul

Reputation: 16963

Use str_replace to remove all occurrences of \ and u00a0 from your json string, like this:

echo str_replace('u00a0', '', str_replace('\\', '', $json_string));

Output:

AS_applicant_Data__c":"{"Full Name":"asdffas"}"}  

Upvotes: 2

Related Questions