proger89/convert-types

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

This package is auto-updated.

Last update: 2024-04-12 14:05:54 UTC


README

Convert to different formats.

For instance:

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

etc.

HTML to JSON

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

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

or use to constant

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

JSON to 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')

or use to constant

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