This looks a little JSONP-ish, so it actually should be valid JSON, except that it's wrapped within a funtion call. But that comma at the end of "domain": "http://www.google.com/",
sure does not belong there.
You have several ways to go about it:
- strip the function wrapper
This only works if you know the function name. So if you know that it'll always be wrapped with WebInfo(...)
, you could just extract the JSON-part substring:
$jsonPart = substr($jsonpString, 8, -1);
where 8 is the length of "WebInfo(" and "-1" takes care of the ")" at the end.
- Parse the JSON-part
Simply parse everything between the first "{" and the last "}":
preg_match("/\{(.*)\}/s", $jsonpString, $matches);
Since there should only be one match, you grab the first:
$jsonPart = $matches[0];
With this approach you don't need to know the wrapper-function name's name/length. But still you need to take care of that trailing comma mentioned above. Is it really there or was it just a copy-paste mistake?