I am fairly new to Laravel as well as PHP in general. The following code is working, but I want to be able to change the way the xml data parses into the array depending on the id that is passed in to the parseXML function.
<?php namespace Podguest\Feed;
use Podguest\Feed\TimeFormat;
class FeedConnect {
public function fetch($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
$this->xml = new \SimpleXMLElement ($output);
return $this->xml;
}
public function parseXML($xml, $id)
{
$data = [];
$i = 0;
foreach ($xml->channel->item as $item) {
$namespace = $item->getNameSpaces(true);
$itunes = $item->children($namespace['itunes']);
$data[$i++] = [
'number' => preg_replace('/^.*#|\s-.*/', '', (string)$item->title),
'title' => (string)$item->title,
'pub_date' => date_format(date_create_from_format('D, d M Y H:i:s O', (string)$item->pubDate),'m/d/Y'),
'duration' => TimeFormat::convertSeconds((string)$itunes->duration),
'description' => (string)$item->description,
'guests' => preg_replace('/^.* - |,? &.*|, \bme\b/i', '', (string)$item->title),
'url' => (string)$item->link
];
}
return $this->data = $data;
}
}
I have no clue what the best way to do this is. I wanted to store them in the mySQL database, but that is not a good idea from what I've read about eval(). What are my other options?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community