UPDATED SOLUTION BELOW
Here is the supposed json:
a: 14: {
s: 9: "rating_id";s: 24: "rwp_rating_5aafe3e80b03d";s: 14: "rating_post_id";i: 3293;s: 16: "rating_review_id";s: 32: "14855d71ef49debd6f9493c13b1bf84b";s: 12: "rating_score";a: 1: {
i: 0;d: 5;
}
s: 14: "rating_user_id";i: 2;s: 16: "rating_user_name";s: 0: "";s: 17: "rating_user_email";s: 0: "";s: 12: "rating_title";s: 0: "";s: 14: "rating_comment";s: 11: "dsfusof9832";s: 13: "rating_images";a: 0: {}
s: 11: "rating_date";i: 1521476584;s: 13: "rating_status";s: 7: "pending";s: 15: "rating_verified";b: 0;s: 15: "rating_template";s: 26: "rwp_template_5a1d7fcb9457e";
}
However, when I checked it with JSONLint, it does not validate. I receive the error:
Error: Parse error on line 1: a: 14: { s: 9: "rat ^ Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
I need to extract the value of "rating_comment"
Can someone help make this valid JSON or help to extract the value of "rating_comment"?
SOLUTION
I did not know that this was serialized string and NOT JSON. Thank you for pointing that out to me. I will use unserialize to get the data I need. :)
You have to use unserialize()
to get your value. But your string is not a valid serialized string. You have to remove extra spaces, and linebreaks (the string cannot be changed like JSON).
$serial='a:14:{s:9:"rating_id";s:24:"rwp_rating_5aafe3e80b03d";s:14:"rating_post_id";i:3293;s:16:"rating_review_id";s:32:"14855d71ef49debd6f9493c13b1bf84b";s:12:"rating_score";a:1:{i:0;d:5;}s:14:"rating_user_id";i:2;s:16:"rating_user_name";s:0:"";s:17:"rating_user_email";s:0:"";s:12:"rating_title";s:0:"";s:14:"rating_comment";s:11:"dsfusof9832";s:13:"rating_images";a:0:{}s:11:"rating_date";i:1521476584;s:13:"rating_status";s:7:"pending";s:15:"rating_verified";b:0;s:15:"rating_template";s:26:"rwp_template_5a1d7fcb9457e";}';
$obj=unserialize($serial);
echo $obj['rating_comment'];
Outputs:
dsfusof9832