有什么方法可以在PHP中将json转换为xml吗? [英] Is there any way to convert json to xml in PHP?

查看:89
本文介绍了有什么方法可以在PHP中将json转换为xml吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以将PHP中的json转换为xml?我知道xml到json的可能性很大.

Is there any way to convert json to xml in PHP? I know that xml to json is very much possible.

推荐答案

如果您愿意使用通过PEAR的XML Serializer ,您可以通过两个简单的步骤将JSON转换为PHP对象,然后将PHP对象转换为XML:

If you're willing to use the XML Serializer from PEAR, you can convert the JSON to a PHP object and then the PHP object to XML in two easy steps:

include("XML/Serializer.php");

function json_to_xml($json) {
    $serializer = new XML_Serializer();
    $obj = json_decode($json);

    if ($serializer->serialize($obj)) {
        return $serializer->getSerializedData();
    }
    else {
        return null;
    }
}

这篇关于有什么方法可以在PHP中将json转换为xml吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆