Hi I thought i would share this in case some one could make it simpler as i know some are you are more profient than me with tyour curls and things
<?php
// * Create SSQL Entry from FTP delivery
// *
/*
<?xml version="1.0" encoding="utf-8"?>
<PLAYER name="RadioBOSS" version="6.2.3.2">
<TRACK ARTIST="Morcheeba" TITLE="The Sea" ALBUM="Parts of the Process" YEAR="2003" GENRE="Lush;downbeat;" COMMENT="Ripped by Winamp" FILENAME="C:\Music & Video\Morcheeba - Parts of the Process\01 - Morcheeba - The Sea.mp3" DURATION="05:49" STARTED="2022-12-19 01:37:03" PLAYCOUNT="4" LASTPLAYED="2022-12-19 01:37:02" INTRO="0.00" OUTRO="0.00" LANGUAGE="" RATING="0" BPM="150" TAGS="" F1="" F2="" F3="" F4="" F5="" CASTTITLE="Morcheeba - The Sea" LISTENERS="0" />
<PREVTRACK><TRACK ARTIST="Metric" TITLE="Nobody Home" ALBUM="Fantasies" YEAR="2009" GENRE="Lush; Rock; Indie Rock; New Wave;" COMMENT="
http://mp3caprice.com" FILENAME="C:\Music & Video\Metric - Fantasies\14_nobody-home.mp3" DURATION="03:13" STARTED="2022-12-19 01:37:03" PLAYCOUNT="13" LASTPLAYED="2022-12-19 01:34:14" INTRO="182.68" OUTRO="1.26" LANGUAGE=" English" RATING="6" BPM="166" TAGS="" F1="" F2="" F3="" F4="" F5="" CASTTITLE="Metric - Nobody Home" /></PREVTRACK>
</PLAYER>
*/
//exit(); /*************************************************** TERMINATE ********************************************/
$baseurl = "
http://deniserose.ezyro.com/";
$servername = "sql306.ezyro.com";
$username = "ezyro_33672165";
$password="4hzhjvr1s2";
$dbname = "ezyro_33672165_song_history";
$filename = "images/nowplaying.txt";
$artwork_filename = "images/nowplaying.txt";
$textXML = "";
$title = "";
$artist = "";
$album = "";
$length = "";
$bpm = "";
$genre = "";
$listeners = "";
$comment = "";
$artwork = "";
$lyrics="";
$search = ["À","Á" ,"Â" ,"Ã","Ä","Å","à","á","â","ã","ä","å","Æ","æ","ß","Ç","ç","È","É","Ê","Ë","è","é","ê","ë","ƒ","Ì","Í","Î","Ï","ì","í","î","ï","Ñ","ñ","Ò","Ó","Ô","Õ","Ö","ò","ó","ô","õ","ö","Ø","ø","Œ","œ","Š","š","Ù","Ú","Û","Ü","ù","ú","û","ü","µ","×","Ý","Ÿ","ý","ÿ","°","†","‡","<",">","±","«","»","¿","¡","·","•", "™","©","®","§" ];
$replace = ["À","Á","Â","Ã","Ä","Å","à","á","â","ã","ä","å","Æ","æ","ß","Ç","ç","È","É","Ê","Ë","è","é","ê","ë","ƒ","Ì","Í","Î","Ï","ì","í", "î","ï","Ñ","ñ","Ò","Ó","Ô","Õ","Ö","ò","ó","ô","õ","ö","Ø","ø","Œ","œ","Š","š","Ù","Ú","Û","Ü","ù","ú","û","ü","µ","×","Ý","Ÿ","ý","ÿ","°","†","‡","<",">","±","«","»","¿","¡","·","•","™","©","®","§"];
function cleanup($str) {
return str_replace($search,$replace,$str);
}
$pattern_replace = array (
"À" => "À",
"Á" => "Á",
"Â" => "Â",
"Ã" => "Ã",
"Ä" => "Ä",
"Å" => "Å",
"à" => "à",
"á" => "á",
"â" => "â",
"ã" => "ã",
"ä" => "ä",
"å" => "å",
"Æ" => "Æ",
"æ" => "æ",
"ß" => "ß",
"Ç" => "Ç",
"ç" => "ç",
"È" => "È",
"É" => "É",
"Ê" => "Ê",
"Ë" => "Ë",
"è" => "è",
"é" => "é",
"ê" => "ê",
"ë" => "ë",
"ƒ" => "ƒ",
"Ì" => "Ì",
"Í" => "Í",
"Î" => "Î",
"Ï" => "Ï",
"ì" => "ì",
"í" => "í",
"î" => "î",
"ï" => "ï",
"Ñ" => "Ñ",
"ñ" => "ñ",
"Ò" => "Ò",
"Ó" => "Ó",
"Ô" => "Ô",
"Õ" => "Õ",
"Ö" => "Ö",
"ò" => "ò",
"ó" => "ó",
"ô" => "ô",
"õ" => "õ",
"ö" => "ö",
"Ø" => "Ø",
"ø" => "ø",
"Œ" => "Œ",
"œ" => "œ",
"Š" => "Š",
"š" => "š",
"Ù" => "Ù",
"Ú" => "Ú",
"Û" => "Û",
"Ü" => "Ü",
"ù" => "ù",
"ú" => "ú",
"û" => "û",
"ü" => "ü",
"µ" => "µ",
"×" => "×",
"Ý" => "Ý",
"Ÿ" => "Ÿ",
"ý" => "ý",
"ÿ" => "ÿ",
"°" => "°",
"†" => "†",
"‡" => "‡",
"<" => "<",
">" => ">",
"±" => "±",
"«" => "«",
"»" => "»",
"¿" => "¿",
"¡" => "¡",
"·" => "·",
"•" => "•",
"™" => "™",
"©" => "©",
"®" => "®",
"§" => "§"
);
function str_replace_json($search, $replace, $output){
return json_decode(str_replace($search, $replace, json_encode($output)));
}
function replace_chars_with_entities( $str )
{
$str = str_replace( 'À', 'À', $str );
$str = str_replace( 'Á', 'Á', $str );
$str = str_replace( 'Â', 'Â', $str );
$str = str_replace( 'Ã', 'Ã', $str );
$str = str_replace( 'Ä', 'Ä', $str );
$str = str_replace( 'Å', 'Å', $str );
$str = str_replace( 'Æ', 'Æ', $str );
$str = str_replace( 'Ç', 'Ç', $str );
$str = str_replace( 'È', 'È', $str );
$str = str_replace( 'É', 'É', $str );
$str = str_replace( 'Ê', 'Ê', $str );
$str = str_replace( 'Ë', 'Ë', $str );
$str = str_replace( 'Ì', 'Ì', $str );
$str = str_replace( 'Í', 'Í', $str );
$str = str_replace( 'Î', 'Î', $str );
$str = str_replace( 'Ï', 'Ï', $str );
$str = str_replace( 'Ð', 'Ð', $str );
$str = str_replace( 'Ñ', 'Ñ', $str );
$str = str_replace( 'Ò', 'Ò', $str );
$str = str_replace( 'Ó', 'Ó', $str );
$str = str_replace( 'Ô', 'Ô', $str );
$str = str_replace( 'Õ', 'Õ', $str );
$str = str_replace( 'Ö', 'Ö', $str );
$str = str_replace( '×', '×', $str );
$str = str_replace( 'Ø', 'Ø', $str );
$str = str_replace( 'Ù', 'Ù', $str );
$str = str_replace( 'Ú', 'Ú', $str );
$str = str_replace( 'Û', 'Û', $str );
$str = str_replace( 'Ü', 'Ü', $str );
$str = str_replace( 'Ý', 'Ý', $str );
$str = str_replace( 'Þ', 'Þ', $str );
$str = str_replace( 'ß', 'ß', $str );
$str = str_replace( 'à', 'à', $str );
$str = str_replace( 'á', 'á', $str );
$str = str_replace( 'â', 'â', $str );
$str = str_replace( 'ã', 'ã', $str );
$str = str_replace( 'ä', 'ä', $str );
$str = str_replace( 'å', 'å', $str );
$str = str_replace( 'æ', 'æ', $str );
$str = str_replace( 'ç', 'ç', $str );
$str = str_replace( 'è', 'è', $str );
$str = str_replace( 'é', 'é', $str );
$str = str_replace( 'ê', 'ê', $str );
$str = str_replace( 'ë', 'ë', $str );
$str = str_replace( 'ì', 'ì', $str );
$str = str_replace( 'í', 'í', $str );
$str = str_replace( 'î', 'î', $str );
$str = str_replace( 'ï', 'ï', $str );
$str = str_replace( 'ð', 'ð', $str );
$str = str_replace( 'ñ', 'ñ', $str );
$str = str_replace( 'ò', 'ò', $str );
$str = str_replace( 'ó', 'ó', $str );
$str = str_replace( 'ô', 'ô', $str );
$str = str_replace( 'õ', 'õ', $str );
$str = str_replace( 'ö', 'ö', $str );
$str = str_replace( '÷', '÷', $str );
$str = str_replace( 'ø', 'ø', $str );
$str = str_replace( 'ù', 'ù', $str );
$str = str_replace( 'ú', 'ú', $str );
$str = str_replace( 'û', 'û', $str );
$str = str_replace( 'ü', 'ü', $str );
$str = str_replace( 'ý', 'ý', $str );
$str = str_replace( 'þ', 'þ', $str );
$str = str_replace( 'ÿ', 'ÿ', $str );
$str = str_replace( "'" , ''', $str );
return $str;
}
// use Square bracket notation $pattern_replace["§"] and
// array_search("§", $pattern_replace, strict) or preg_replace(
if(!isset($conn)) {include("file_operations.php");}
include "mp3/check_remote_server.php";
$remote_server = checkRemoteServerStatus(
"
http://virtualkitten.ds.sparrowindustries.net:27274/",
19200,
0
);
if($remote_server == 0) echo "No server up and available.";
function ReturnError($code, $text)
{
return;
$protocol = isset($_SERVER["SERVER_PROTOCOL"])
? $_SERVER["SERVER_PROTOCOL"]
: "HTTP/1.0";
//header($protocol . ' ' . $code . ' ' . $text);
echo "<HTML>";
echo "<img src ='images/favpng_construction-worker-architectural-engineering-cartoon-royalty-free.png' width='200' height='240'></img><br><br>";
echo "SERVER_PROTOCOL ERROR<BR><BR>";
echo "Add data to SQL -." . $text . "<br><br>";
throw Error("EXIT CODE");
exit();
}
//$remote_server=true;
if ($remote_server == true) {
$xml=simplexml_load_file("images/nowplaying.xml");
if( $xml == false) {ReturnError(500, "Failed to open ("."images/nowplaying.xml".") bytes of XML from file XML.");}
//$artist= iconv( "UTF-8", "ISO-8859-1//TRANSLIT", $artist); //TO REMOVE THE ISO-8859-1 ISSUE
//print_r($xml);
$title = implode($xml->xpath('//PLAYER/TRACK/@TITLE'));
$title = replace_chars_with_entities($title);
$artist = implode($xml->xpath('//PLAYER/TRACK/@ARTIST'));
$artist = replace_chars_with_entities($artist );
$album = implode($xml->xpath('//PLAYER/TRACK/@ALBUM'));
$year = implode($xml->xpath('//PLAYER/TRACK/@YEAR'));
$album = replace_chars_with_entities($album );
$genre = implode($xml->xpath('//PLAYER/TRACK/@GENRE'));
$comment = implode($xml->xpath('//PLAYER/TRACK/@COMMENT'));
$bpm = implode($xml->xpath('//PLAYER/TRACK/@BPM'));
$length = implode($xml->xpath('//PLAYER/TRACK/@DURATION'));
$listeners =implode($xml->xpath('//PLAYER/TRACK/@LISTENERS'));
$rating = implode($xml->xpath('//PLAYER/TRACK/@RATING'));
$lyrics = implode($xml->xpath('//PLAYER/TRACK/@LYRICS'));
$exit_old = false;
print_r($lyrics);
$parts = preg_split('/(?=[A-Z])/', $lyrics, -1, PREG_SPLIT_NO_EMPTY);
echo "<br><br>";
$xml = null; // clear the used class XML.
// note there is now num_rows in PDO so we have to calculate a new one to get record number.
$n = 0;
$result = OpenPDO($conn,"SELECT * FROM `played_songs` ORDER BY `datetime` DESC LIMIT 1",$_query,"");
$row = $result->fetch();
if ($artist != $row['artist'] && $title != $row['song']) {
$exit_old = true;
$t = fopen("images/nowplaying_artwork_2.png", "r");
if ($t !== false) {
$artwork = fread($t, filesize("images/nowplaying_artwork_2.png"));
fclose($t);
} else {
fclose($t);
ReturnError(500, "Failed to write artwork to a file.");
}
$base64artwork = base64_encode($artwork);
try {
$sql = "INSERT INTO `played_songs` (`song`, `artist`, `album`, `length`, `bpm`,`genre`, `listeners`,`track_user_rating`,`track_user_num`,`comment`,`ImageBase64`,`lyrics`,`year`) VALUES ('$title','$artist', '$album', '$length', '$bpm', '$genre','$listeners','0','0', '$comment','$base64artwork','','$year') ON DUPLICATE KEY UPDATE `listeners`='$listeners'";
$result= OpenPDO($conn,$sql,$_execute,"");
} catch(Exception $e) {
//$result->rollBack();
ReturnError($code, "An Error occurd inserting record to SQL");
}
try {
$sql ="UPDATE `played_songs` SET `lyrics` = '$lyrics' WHERE datetime = (select max(datetime) FROM `played_songs`)";
$result= OpenPDO($conn,$sql,$_execute,"");
} catch(Exception $e) {
//$result->rollBack();
ReturnError($code, "An Error occurd updatig record in SQL");
}
$result = OpenPDO($conn,"SELECT COUNT(`datetime`) FROM `played_songs` ORDER BY `datetime` ASC",$_query,"");
$row = $result->fetch();
$n = $row["COUNT(`datetime`)"] - 300;
if ($n > 1) {
$q = OpenPDO($conn,"SELECT `datetime` FROM `played_songs` ORDER BY `datetime` ASC",$_query,"");
while ($n) {
$r = $q->fetch();
$id = $r["datetime"];
OpenPDO($conn,"DELETE FROM `played_songs` WHERE `datetime`=?" ,$_execute,$id);
$n--;
}
}
} else {
ReturnError(500,"Failed to write/read record to SQL. NO data read from the XML file");
}
//echo "New record created successfully";
} else {
ReturnError(500, "Failed to write /read from xml file no data was loaded." );
}
//Server disconnected
?>
</HTML>