B
B
Boris Boyko2016-08-02 05:00:46
PHP
Boris Boyko, 2016-08-02 05:00:46

How to fix JSON error?

The task is simple - to parse the podcast feed. Here is the code:

<?php
$response = array("error" => FALSE);
$response["feed"] = array();
$url = "https://mayk.podfm.ru/rss";
$xml = simplexml_load_file($url);
for($i = 0; $i < 20; $i++){

   $title = $xml->channel->item[$i]->title;
   $pubDate = $xml->channel->item[$i]->pubDate;
   $enclosure = $xml->channel->item[$i]->enclosure['url'];
   
   $url = rtrim($enclosure, "?channel=rss");

   $product = array();
   $product["pod"]["title"] = $title;
   $product["pod"]["date"] = $pubDate;
   $product["pod"]["song"] = $url;

   array_push($response["feed"], $product);
}

   echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
?>

But at the output I get 8b7df3f36b274614a7e0f626c28849ef.png
Where does "0" come from?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2016-08-02
@Fibonachy

Where does "0" come from?
do
$title = $xml->channel->item[$i]->title;var_dump($title);exit;
and understand.
How to fix
$title = (string)$xml->channel->item[$i]->title;if fast.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question