proger89/convert-types

dev-main 2023-01-12 11:24 UTC

This package is auto-updated.

Last update: 2024-09-12 15:03:19 UTC


README

转换不同格式。

例如

  • XML -> JSON
  • JSON -> XML
  • HTML -> JSON
  • HTML -> XML

等等。

HTML 转换为 JSON

$html = "<html><body>Hello <i>This is my car</i></body></html>"

$convert = new Convert();
print $convert->to($html,'json') 

或用于常数

$convert = new Convert();
print $convert->to($html,Convert::TYPE_JSON)

JSON 转换为 XML

$json = "[
	{
		color: "red",
		value: "#f00"
	},
	{
		color: "green",
		value: "#0f0"
	},
	{
		color: "blue",
		value: "#00f"
	},
	{
		color: "cyan",
		value: "#0ff"
	},
	{
		color: "magenta",
		value: "#f0f"
	},
	{
		color: "yellow",
		value: "#ff0"
	},
	{
		color: "black",
		value: "#000"
	}
]"

$convert = new Convert();
print $convert->to($html,'xml')

或用于常数

$convert = new Convert();
print $convert->to($html,Convert::TYPE_XML)