Support the ongoing development of Laravel.io →
Requests Database

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?

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

mjoconnor mjoconnor Joined 6 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.