3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DudenResponse { protected $response; public function __construct($response) { $this->response = $response; $this ->stripShit() ->decode() ->mockXML(); } protected function stripShit() { $this->response = substr($this->response, 36-1); return $this; } protected function decode() { $response = preg_replace("/\\\\u([0-9a-f]{3,4})/i", "&#x\\1;", $this->response); $this->response = html_entity_decode($response, null, 'UTF-8'); return $this; } protected function mockXML() { $this->response = str_replace([ '<?dpf ', ' ?>', '?>' ], [ '<', '>', '>' ], $this->response); return $this; } public function toArray() { $xml = simplexml_load_string($this->toString()); $array = []; foreach ($xml as $node) { $array[(string) $node] = explode(';', $node->attributes()['prop']); } return $array; } public function toString() { return $this->response; } public function __toString() { return $this->toString(); } } $response = "0;78d13qqoglyszmorspfwfdmwffgnubgr;\u003c?dpf sent len=\"1\"?\u003e\u003c?dpf orth code=\"unknown\" prop=\"Lesen;Lehnen;Lehren;Leasen;Leisen\" ?\u003elehsen\u003c?dpf /orth ?\u003e\u003c?dpf /sent ?\u003e"; $response = new DudenResponse($response); echo $response; echo "\n\n-----\n\n"; print_r($response->toArray());

preferences:
33.04 ms | 402 KiB | 5 Q