OK, so I was able to get the result that I was looking for. However, when I went to implement it on the final page, I'm having a problem. Instead of returning the folder name, it is returning the word "array."
The working code below returns:
http://www.recastgweb.com/media/Luke
Luke
<?php
$entry = 'http://www.recastgweb.com/media/Luke/Luke14_01-14.mp3';
$path = pathinfo($entry);
echo $path['dirname'], "\n <br />";
echo $path['basename'], "\n <br />";
echo $path['extension'], "\n <br />";
echo $path['filename'], "\n <br />";
$string=$path['dirname'];
echo $string, "\n <br />";
$path1 = pathinfo($string);
echo $path1['basename'], "\n <br />";
?>
When I apply that to my final code I get this returned:
=============== ITEM DATA ==============
Title: Luke: Amongst the Highways and Hedges (01/29/12)
Description: Pastor Albert Lee teaches from Luke 14:15-24
Link: http://www.recastweb.com/media/Luke/Luke14_15-24.mp3
GUID: 67BEFCBA-A0F2-4B1F-997A-92824DF3E6AF
Folder: Array
Enclosure URL: http://www.recastweb.com/media/Luke/Luke14_15-24.mp3
Enclosure Size: 22512965
Enclsoure Type: audio/mpeg
PubDate: Tue, 31 Jan 2012 17:26:53
pubZoneOffset: -0800
=============== ITUNES DATA ==============
author: Albert Lee @ Regeneration
keywords: regeneration, Albert Lee, Holy Bible, New Testiment, Jesus, Gospel, Luke
duration: 53:02
subtitle: Luke: Amongst the Highways and Hedges (01/29/12)
summary: Pastor Albert Lee teaches from Luke 14:15-24
isClosedCaptioned: no
blockEpisode: no
Episodes were added.
Here is the implementation:
<html>
<head>
<title>Tag Parser</title>
<!-- <form name="configform" action="parser.php?action=saveconfig" method="POST">
<fieldset style="width: 650px;">
<legend>Results</legend>
-->
<?php
$myFile = '
<item>
<title>Luke: Amongst the Highways and Hedges (01/29/12)</title>
<link>http://www.recastweb.com/media/Luke/Luke14_15-24.mp3</link>
<description>Pastor Albert Lee teaches from Luke 14:15-24</description>
<pubDate>Tue, 31 Jan 2012 17:26:53 -0800</pubDate>
<guid isPermaLink="false">67BEFCBA-A0F2-4B1F-997A-92824DF3E6AF</guid>
<enclosure url="http://www.recastweb.com/media/Luke/Luke14_15-24.mp3" length="22512965" type="audio/mpeg" />
<itunes:author>Albert Lee @ Regeneration</itunes:author>
<itunes:image href="http://www.recastweb.com/images/GospelOfLuke300.png" />
<itunes:keywords>regeneration, Albert Lee, Holy Bible, New Testiment, Jesus, Gospel, Luke</itunes:keywords>
<itunes:duration>53:02</itunes:duration>
<itunes:subtitle>Luke: Amongst the Highways and Hedges (01/29/12)</itunes:subtitle>
<itunes:summary>Pastor Albert Lee teaches from Luke 14:15-24</itunes:summary>
</item>';
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
$strCode = $myFile;
if (preg_match_all('%<item>.*?</item>%si',$strCode,$regs)) {
$aryItems = $regs[0];
foreach($aryItems as $strItem) {
$strTitle = '';
$strDescription = '';
$entry = '';
$strLink = '';
$strGUID = '';
$strEnclosureURL = '';
$intEnclosureLength = '';
$strEnclosureType = '';
$strPubDate = '';
$strpubZoneOffset = '';
$strblockEpisode = 'no';
$strisClosedCaptioned ='no';
$aryItuneData = array();
if (preg_match('%<title>(.*?)</title>%si',$strItem,$regs)) {
$strTitle = $regs[1];
}
if (preg_match('%<description>(.*?)</description>%si',$strItem,$regs)) {
$strDescription = $regs[1];
}
if (preg_match('%<link>(.*?)</link>%si',$strItem,$regs)) {
$entry = $regs[1];
$path = pathinfo($entry);
$string=$path['dirname'];
$folder = pathinfo($string);
// $folder = pathinfo($folderB);
}
if (preg_match('%<link>(.*?)</link>%si',$strItem,$regs)) {
$strLink = $regs[1];
}
if (preg_match('%<guid isPermaLink=\"false\">(.*?)</guid>%si',$strItem,$regs)) {
$strGUID = $regs[1];
}
if (preg_match('%<pubDate>(.*?)</pubDate>%si',$strItem,$regs)) {
$strPubDate = date('D, d M Y H:i:s',strtotime($regs[1]));
}
if (preg_match('%<pubDate>(.*?)</pubDate>%si',$strItem,$regs)) {
$strpubZoneOffset = date('O',strtotime($regs[1]));
}
// if (preg_match('%<enclosure url="([^"]*?)" length="([^"]*?)" type="([^"]*?)".*?</enclosure>.%si',$strItem,$regs)) //use for </enclosure>
// {
if (preg_match('%<enclosure url="([^"]*?)" length="([^"]*?)" type="([^"]*?)".*?/>.%si',$strItem,$regs)) //use for />
{
$strEnclosureURL = $regs[1];
$intEnclosureLength = (int)$regs[2];
$strEnclosureType = $regs[3];
}
if (preg_match_all('%<itunes:([^>]+)>(.*?)</itunes:\1>%si',$strItem,$regs)) {
foreach($regs[2] as $index=>$val) {
$aryItuneData[$regs[1][$index]] = $val;
}}
echo "\n=============== ITEM DATA ==============\n <br />";
echo "Title: $strTitle\n <br />";
echo "Description: $strDescription\n <br />";
echo "Link: $strLink\n <br />";
echo "GUID: $strGUID\n <br />";
echo "Folder: $folder\n <br />";
echo "Enclosure URL: $strEnclosureURL\n <br />";
echo "Enclosure Size: $intEnclosureLength\n <br />";
echo "Enclsoure Type: $strEnclosureType\n <br />";
echo "PubDate: $strPubDate\n <br />";
echo "pubZoneOffset: $strpubZoneOffset\n <br />";
echo "<br />";
echo "\n=============== ITUNES DATA ==============\n <br />";
foreach($aryItuneData as $key=>$val)
echo "\t$key: $val\n <br />";{
echo "isClosedCaptioned: $strisClosedCaptioned\n <br />";
echo "blockEpisode: $strblockEpisode\n <br />";}
echo "------------------------------------------------------\n <br />";
$emptyExplicit = 'no';
$con = mysql_connect("localhost","user","password");
mysql_select_db("podadmin", $con);
// insertion into episodes table
$query = "INSERT INTO import (guid, title, subtitle, keywords, explicit, isClosedCaptioned, author, description, pubdate, pubZoneOffset, blockEpisode, size, duration, folder, filename)";
$query .= "VALUES (";
$query .= "'" . mysql_real_escape_string(basename($strGUID)) . "', " .
"'" . mysql_real_escape_string($strTitle) . "', " .
"'" . mysql_real_escape_string($aryItuneData['subtitle']) . "', " .
"'" . mysql_real_escape_string($aryItuneData['keywords']) . "', " .
"'" . mysql_real_escape_string($emptyExplicit) . "', " .
"'" . mysql_real_escape_string($strisClosedCaptioned) . "', " .
"'" . mysql_real_escape_string($aryItuneData['author']) . "', " .
"'" . mysql_real_escape_string($strDescription) . "', " .
"FROM_UNIXTIME('" . strtotime(mysql_real_escape_string($strPubDate)) . "'), " .
"'" . mysql_real_escape_string($strpubZoneOffset) . "', " .
"'" . mysql_real_escape_string($strblockEpisode) . "', " .
"'" . mysql_real_escape_string($intEnclosureLength) . "', " .
"'" . mysql_real_escape_string($aryItuneData['duration']) . "', " .
"'" . mysql_real_escape_string(basename($folder)) . "', " .
"'" . mysql_real_escape_string(basename($strLink)) . "')";
if ( ! mysql_query($query) ) {
exit("Query failed! - $query<Br>" . mysql_error());
}
// CHECKING FOR DUPLICATE GUID ENTRIES IN XML FILE
$emptyExplicit = 'no';
$con = mysql_connect("localhost","user","password");
mysql_select_db("podadmin", $con);
// insertion into guid table
$query = "INSERT INTO guid (guid, filename) ";
$query .= "VALUES (";
$query .= "'" . mysql_real_escape_string(basename($strGUID)) . "', " .
"'" . mysql_real_escape_string(basename($strLink)) . "')";
if ( ! mysql_query($query) ) {
exit("Query failed! - $query<Br>" . mysql_error());
}
}
}
print "<p style='color: green'>Episodes were added.</p>\n";
mysql_close($con);
?>
</html>
To my eyes I'm not seeing a difference regarding getting the Folder to return Luke, rather than array. If I simply assign $folder = $path['dirname']; then it prints out
http://www.recastweb.com/media/Luke
Thanks for looking,
Robert