Answer the question
In order to leave comments, you need to log in
How can you parse such a string?
Good evening.
How can you parse such a string using PHP? I'm interested in getting the Result parameter from a tag.
<html><content></content><json><![CDATA[{"type":"datasource", "Result":true,"HasVKBinding":true}]]><![CDATA[{"type":"webparams", "ClientScriptId":"string-CommonController","ContainerId":"string-CommonController","ClientControlClass":"string-CommonController","DisableDomRendering":"bool-False","ExpireMinutes":"integer-0"}]]></json></html>
Answer the question
In order to leave comments, you need to log in
You can use simplexml_load_string . The output will be an object that is easier to work with.
$xml = simplexml_load_string('<html><content></content><json><![CDATA[{"type":"datasource", "Result":true,"HasVKBinding":true}]]><![CDATA[{"type":"webparams", "ClientScriptId":"string-CommonController","ContainerId":"string-CommonController","ClientControlClass":"string-CommonController","DisableDomRendering":"bool-False","ExpireMinutes":"integer-0"}]]></json></html>');
$array_from_json = json_decode($xml->json, 1);
If the string construction is always the same, then you can do this:
$html = 'ваша_строка';
preg_match('/"Result":(.*?),/is', $html, $m);
$result = $m[1];
var_dump($result); /* string(4) "true" */
$html = 'ваша_строка';
preg_match('/CDATA\[(.*?)\]/is', $html, $m);
$json = $json = json_decode($m[1], true);
$result = $json['Result'];
var_dump($result); /* bool(true) */
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question