Git Product home page Git Product logo

type-converter's Introduction

Type Converter v2.0.0

A class that handles the detection and conversion of certain resource formats / content types into other formats. The current formats are supported: XML, JSON, Array, Object, Serialized

Requirements

Documentation

The class is pretty straight forward. If you want to convert something to another format, use the "to" methods.

$object = TypeConverter::toObject($resource);
$array = TypeConverter::toArray($resource);
$json = TypeConverter::toJson($resource);
$xml = TypeConverter::toXml($resource);
$ser = TypeConverter::toSerialize($resource);

If you want to detect what resource type it is, use the "is" methods. If you use the "to" methods above, it does automatic "is" detection.

TypeConverter::isObject($resource);
TypeConverter::isArray($resource);
TypeConverter::isJson($resource);
TypeConverter::isXml($resource);
TypeConverter::isSerialized($resource);

If you want a string representation of what a resource is, use the default is() method.

$resource = array();
TypeConverter::is($resource); // array

Finally, you can convert an XML document into an array (must have SimpleXML).

$array = TypeConverter::xmlToArray($xml, TypeConverter::XML_MERGE);

When using xmlToArray(), you can define the format in which the node attributes and values are presented. The following constants are available.

XML_NONE  - Disregard XML attributes and only return the value.
XML_MERGE - Merge attributes and the value into a single dimension; the values key will be "value".
XML_GROUP - Group the attributes into a key of "attributes" and the value into a key of "value".
XML_OVERWRITE - Attributes will only be returned.

Be sure to set the content type when supporting UTF-8.

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

type-converter's People

Contributors

kohaku1907 avatar milesj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.