Удалите некоторую информацию в переменной json с php

Моя проблема в том, что я разбираю XML-файл, и этот файл содержит некоторую информацию, которую я не хочу экспортировать как данные JSON. В моем случае я хочу функцию, которая возвращает данные json из первого '[' caratere, это код php:

<?php class XmlToJsonConverter { public function ParseXML ($url) { $fileContents= file_get_contents($url); // Remove tabs, newline, whitespaces in the content array $fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents); $fileContents = trim(str_replace('"', "'", $fileContents)); $myXml = simplexml_load_string($fileContents); $json = json_encode($myXml); return $json; } } //Path of the XML file $url= 'http://www.lequipe.fr/rss/actu_rss_Football.xml'; //Create object of the class $jsonObj = new XmlToJsonConverter(); //Pass the xml document to the class function $myjson = $jsonObj->ParseXMl($url); print_r ($myjson); ?> 

это часть результата JSON:

{"@attributes": {"version": "2.0"}, "channel": {"title": "L'Equipe.fr Actu Football", "link": "http://www.lequipe.fr" , «описание»: «L'Equipe.fr, Toute l'actualit \ u00e9 du football», «language»: «fr», «copyright»: «Copyright L'Equipe.fr», «pubDate»: «Ср, 22 Apr 2015 16:31:08 +0200 "," image ": {" url ":" http://img.ruphp.com/php/logo_RSS.gif "," title ":" L'Equipe.fr " , "link": "http://www.lequipe.fr", "width": "119", "height": "28"}, "item": [{"title": "Foot-Cha

я хочу, чтобы результат начинался с '['

спасибо

Solutions Collecting From Web of "Удалите некоторую информацию в переменной json с php"

Удалите все атрибуты, которые вы не хотите, перед кодировкой json:

 public function ParseXML ($url) { $fileContents= file_get_contents($url); // Remove tabs, newline, whitespaces in the content array $fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents); $fileContents = trim(str_replace('"', "'", $fileContents)); $myXml = simplexml_load_string($fileContents); //-------------- unset($myXml['@attributes']); unset($myXml['channel']); unset($myXml['image']); //-------------- $json = json_encode($myXml); return $json; } с public function ParseXML ($url) { $fileContents= file_get_contents($url); // Remove tabs, newline, whitespaces in the content array $fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents); $fileContents = trim(str_replace('"', "'", $fileContents)); $myXml = simplexml_load_string($fileContents); //-------------- unset($myXml['@attributes']); unset($myXml['channel']); unset($myXml['image']); //-------------- $json = json_encode($myXml); return $json; } с public function ParseXML ($url) { $fileContents= file_get_contents($url); // Remove tabs, newline, whitespaces in the content array $fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents); $fileContents = trim(str_replace('"', "'", $fileContents)); $myXml = simplexml_load_string($fileContents); //-------------- unset($myXml['@attributes']); unset($myXml['channel']); unset($myXml['image']); //-------------- $json = json_encode($myXml); return $json; } с public function ParseXML ($url) { $fileContents= file_get_contents($url); // Remove tabs, newline, whitespaces in the content array $fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents); $fileContents = trim(str_replace('"', "'", $fileContents)); $myXml = simplexml_load_string($fileContents); //-------------- unset($myXml['@attributes']); unset($myXml['channel']); unset($myXml['image']); //-------------- $json = json_encode($myXml); return $json; } 

или если вам нужен только элемент:

 public function ParseXML ($url) { $fileContents= file_get_contents($url); // Remove tabs, newline, whitespaces in the content array $fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents); $fileContents = trim(str_replace('"', "'", $fileContents)); $myXml = simplexml_load_string($fileContents); //-------------- $json = json_encode($myXml['item']); return $json; }