-1

I want to decode this xml string

$string= "%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%20%3CPrintStudentData%20%20name%3D%22John%20Doe%22%20marks%3D%2298%22%20%2F%3E";

I tried echo urldecode($string); but it is not printing anything.

Expected Output

<?xml version="1.0" encoding="UTF-8"?> <PrintStudentData  name="John Doe" marks="98" />

2 Answers2

0

Try

function utf8_urldecode($str) {
    $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));
    return html_entity_decode($str,null,'UTF-8');;
  }
clearshot66
  • 2,292
  • 1
  • 8
  • 17
0

@Michael Scofield just add header("Content-Type: application/xml") to get your desired output like below code, because you have to tell browser that i am going to see xml type content and by that header("Content-Type: application/xml") you can able to see the xml output in the browser:

<?php
$string = "%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%20%3CPrintStudentData%20%20name%3D%22John%20Doe%22%20marks%3D%2298%22%20%2F%3E";
$xml = urldecode ($string);
header("Content-Type: application/xml");
echo $xml;
lazyCoder
  • 2,544
  • 3
  • 22
  • 41