public function toJson($html)
    {
        // Strip white space between tags to prevent creation of empty #text nodes
        $html = preg_replace('~>\s+<~', '><', $html);
        $document = new \DOMDocument();

        // Load UTF-8 HTML hack (from http://bit.ly/pVDyCt)
        $document->loadHTML('<?xml encoding="UTF-8">' . $html);
        $document->encoding = 'UTF-8';

        // fetch the body of the document. All html is stored in there
        $body = $document->getElementsByTagName("body")->item(0);

        $data = array();

        // loop trough the child nodes and convert them
        if ($body) {
            foreach ($body->childNodes as $node) {
                $data[] = $this->convert($node);
            }
        }

        return json_encode(array('data' => $data));
    }
public function toJson($html)
    {
        // Strip white space between tags to prevent creation of empty #text nodes
        $html = preg_replace('~>\s+<~', '><', $html);
        $document = new \DOMDocument();

        // Load UTF-8 HTML hack (from http://bit.ly/pVDyCt)
        $document->loadHTML('<?xml encoding="UTF-8">' . $html);
        $document->encoding = 'UTF-8';

        // fetch the body of the document. All html is stored in there
        $body = $document->getElementsByTagName("body")->item(0);

        $data = array();

        // loop trough the child nodes and convert them
        if ($body) {
            foreach ($body->childNodes as $node) {
                $data[] = $this->convert($node);
            }
        }

        return json_encode(array('data' => $data));
    }
public function toJson ( $ html ) { // Strip white space between tags to prevent creation of empty #text nodes $ html = preg_replace ( '~>\s+<~' , '><' , $ html ) ; $ document = new \ DOMDocument ( ) ; // Load UTF-8 HTML hack (from http://bit.ly/pVDyCt) $ document -> loadHTML ( '<?xml encoding="UTF-8">' . $ html ) ; $ document -> encoding = 'UTF-8' ; // fetch the body of the document. All html is stored in there $ body = $ document -> getElementsByTagName ( "body" ) -> item ( 0 ) ; $ data = array ( ) ; // loop trough the child nodes and convert them if ( $ body ) { foreach ( $ body -> childNodes as $ node ) { $ data [ ] = $ this -> convert ( $ node ) ; } } return json_encode ( array ( 'data' => $ data ) ) ; }
Converts html to the json Sir Trevor requires

@param  string $html
@return string The json string
Converts html to the json Sir Trevor requires