3v4l.org

run code in 300+ PHP versions simultaneously
<?php $_POST['content'] = '<path d="m34.511 143.4v3.0302l54.101-0.63086v-2.078z" points="34.510773,146.42924 88.611514,145.79838 88.611514,143.72037 34.510773,143.39908" fill="#353564"/> <path d="m34.511 146.43 78.119 2.1017 56.193-2.4552-80.211-0.27738z" points="112.6299,148.53093 168.82266,146.07576 88.611514,145.79838 34.510773,146.42924" fill="#afafde"/>'; //first make the post content valid XML $xml = '<xmp>' . $_POST['content'] . '</xmp>'; //load it as a DOMDOcument to parse the desired tags of path $doc = new DOMDocument(); $doc->loadXML($xml); $array = []; //find all of the <path/> tags foreach($doc->getElementsByTagName('path') as $node) { $attributes = []; //convert the attributes into an associative array by attribute name foreach($node->attributes as $attribute) { $attributes[$attribute->name] = $attribute->value; } //store the tag and attributes into array $array[] = (object) [ $node->tagName => $attributes ]; } //convert the PHP array to a JSON string of an array of objects $json = json_encode($array, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT); print_r($json);

preferences:
21.4 ms | 405 KiB | 5 Q