解码php中的xml字符串

时间:2017-04-10 13:28:35

标签: php xml decode urldecode

我想解码这个xml字符串

font-size:5vw!important 

我尝试了$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"; ,但它没有打印任何内容。

预期输出

echo urldecode($string);

2 个答案:

答案 0 :(得分:0)

尝试

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');;
  }

答案 1 :(得分:0)

@Michael Scofield只需添加标题(" Content-Type:application / xml")即可获得所需的输出,如下面的代码,因为你必须告诉浏览器我将看到xml类型的内容和通过该标题(" Content-Type:application / xml"),您可以在浏览器中看到xml输出:

<?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;