campusboy87
11/27/2018 - 11:51 AM

object_js_to_php.php

<?php

$data   = wp_remote_get( 'https://www.tvasites.com/cmswebparts/insite3/api/exporttowordpress.aspx' );
$data   = wp_remote_retrieve_body( $data );
$output = [];

if ( preg_match_all( '/{([^}]*)}/', $data, $matches ) ) {
    foreach ( $matches[1] as $item ) {
        $lines = preg_split( '/\\r\\n?|\\n/', $item, null, PREG_SPLIT_NO_EMPTY );

        if ( is_array( $lines ) ) {
            $lines = array_map( function ( $item ) {
                $line = explode( ': ', $item );

                return '"' . $line[0] . '": "' . trim( $line[1], "'," ) . '",';
            }, $lines );

            $output[] = json_decode( '{' . rtrim( join( '', $lines ), ',' ) . '}' );
        }
    }
}