convert js object to json in php

]*?>(.*?)<\/textarea>/s';

$strHtml= '/]*?>(.*)<\/div>/s';

preg_match($p, $html, $match);
$str = $match[1];
function replaceUnnecessary($strJs)
{
    $str = str_replace(""", "", $strJs);
    $str = str_replace("{", "{\"", $str);
    $str = str_replace(":", "\":\"", $str);
    $str = str_replace(":\"{", ":{", $str);
    $str = str_replace(",", "\",\"", $str);
    $str = str_replace("}\",", "},", $str);
    $str = str_replace("},", "\"},", $str);
    $str = str_replace("\":\"{", "\":{", $str);
    $str = str_replace("]\"", "]", $str);
    $str = str_replace("\"[", "[", $str);
    $str = str_replace("}]", "\"}]", $str);
    return str_replace("}}", "\"}}", $str);
}

function httPreg($matches)
{
    $sub = str_replace("\"", "", $matches[1]);
    return "\":\"" . $sub . "\",\"";
}

$str = preg_replace_callback('/\":\"([^\{\}\]\[]*?)\",\"/', "httPreg", replaceUnnecessary($str));
$jsonData = json_decode($str);

//标的企业名称
echo $jsonData->utrgcemspreobject->objectname . "\n";
//法定代表人
echo $jsonData->utrgcemspreobject->objectboss . "\n";
//注册资本
echo $jsonData->utrgcemspreobject->registeredcapital . "\n";
//经济类型
echo $jsonData->utrgcemspreobject->economytype . "\n";
//企业类型
echo $jsonData->utrgcemspreobject->economynature . "\n";
//经济规模
echo $jsonData->utrgcemspreobject->managerscale . "\n";
//经营范围
echo $jsonData->utrgcemspreobject->businessscope . "\n";

你可能感兴趣的:(convert js object to json in php)