I have been working with json_encode() in PHP and the output is:
{"Inventors:":"Wilson; Nestor Antonio Lagos (Santiago, CL)"}
{"Applicant: ":"Nestor Antonio Lagos Santiago N\/A CL"}
{"Name":"Type"}
And I want the json format like as:
json = {
"Inventors:":"Wilson; Nestor Antonio Lagos (Santiago, CL)",
"Applicant: ":"Nestor Antonio Lagos Santiago N\/A CL",
"Name":"Type"
};
I've tried but always the convertion of my array is the same.
$contents = "<table><tr><td>Row 1 Column 1</td><td>Row 1 Column 2</td></tr><tr><td>Row 2 Column 1</td><td>Row 2 Column 2</td></tr></table>";
$DOM = new DOMDocument;
$DOM->loadHTML($contents);
$items = $DOM->getElementsByTagName('tr');
function tdrows($elements)
{
$str = "";
$i = 0;
foreach ($elements as $element)
{
if($i == 0) {
$itm = $element->nodeValue;
$i++;
} else {
if(strlen($element->nodeValue) > 1 )
$array = array($itm => trim($element->nodeValue));
}
//$str .= $element->nodeValue . ", ";
}
echo json_encode($array);
}