heartburn Posted October 10, 2006 Share Posted October 10, 2006 I have a few files that do the following:1. This one generates an xml file based on the time.2. This file should (in theory) access the first file and get the output of the first file.What is actually happening is that the second file is accessing the first file and spitting out all of the code that I have (for the first file).I know that most people would like to see code rather than just hear me talk so here we go:timeTest.php:[code]<?phperror_reporting(0);// This top area sets the current time, gets the date and names the xml doc$date = date("m/d/Y");$fileDate = date("mdy");$time = date("H:i:s");$xmlFileName = "$fileDate.xml";$default = "default.xml";// This next area will find and open the xml fileif (file_exists($xmlFileName)){ $xml = simplexml_load_file($xmlFileName); trim($xml); countNow($xml, $time, $date); } else { // if the file for today's date is not found, this file will play $xmlFileName = $default; $xml = simplexml_load_file($xmlFileName); trim($xml); countNow($xml, $time, $date);}// This function counts the number of elements in the playlist// when it has that number it moves onto timeNowfunction countNow($xml, $time, $date){ $totalThread=0; foreach($xml->song as $num){ $totalThread++; } timeNow($time, $xml, $date, $totalThread);}// This function will take the time and finds where to start in the playlist// Once it has that it moves onto makeXMLfunction timeNow($time, $xml, $date, $totalThread){ $threadNum = 0; do{ $threadNum++; }while($time>$xml->song[$threadNum]['fileTime']); makeXML($time, $xml, $date, $totalThread, $threadNum);}// This function will create an xml file for the playlist// Once it writes the first few lines it goes to getList for the bulk of the playlistfunction makeXML($time, $xml, $date, $totalThread, $threadNum){ echo "THIS WOULD HOUSE THE XML HEADER BUT IT WAS SCREWING UP THE CODE TAGS IN THE FORUM"; echo "<playlist date=\"$date\">\n"; echo "<song fileDate=\"$date\" fileTime=\"$time\" fileTitle=\"e360live.com Legal ID\" fileArtist=\"e360live.com\" fileSource=\"400000.flv\" nonmusic=\"Y\" fileLabel=\"\" />\n"; getList($time, $xml, $date, $totalThread, $threadNum); echo "</playlist>";}// This function populates the xml list with data from the called xml file// Once it is done, it goes back to makeXML for the closing of the xml filefunction getList($time, $xml, $date, $totalThread, $threadNum){ // This part checks to see if the first file is the 400000.flv, if so it skips it if($xml->song[$threadNum]['fileSource']=='400000.flv'){ $threadNum++; } do{ echo "<song fileDate=\"$date\" fileTime=\"".$xml->song[$threadNum]['fileTime']."\" fileTitle=\"".$xml->song[$threadNum]['fileTitle']."\" fileArtist=\"".$xml->song[$threadNum]['fileArtist']."\" fileSource=\"".$xml->song[$threadNum]['fileSource']."\" nonmusic=\"".$xml->song[$threadNum]['nonmusic']."\" fileLabel=\"".$xml->song[$threadNum]['fileLabel']."\" />\n"; $threadNum++; }while($threadNum<$totalThread);}?>[/code]index.php[code]<?phperror_reporting(0);$info = file_get_contents("timeTest.php");$ctype="application/octet-stream";// disable HTML page caching on the PHP session levelsession_cache_limiter("nocache");header("Expires: 0");// HTTP/1.1// disable browser and proxy cacheheader("Cache-Control: no-store, no-cache, must-revalidate");header("Cache-Control: post-check=0, pre-check=0", false);// HTTP/1.0header("Content-Type: $ctype");header("Pragma: ");echo $info;?>[/code]Alright, so you see the code, but when I run the second one (index.php) instead of printing the output of the file I get the code from timeTest.php (the first file).I take it that I am using the wrong function (file_get_contents)... is there a way to get the xml output instead? Quote Link to comment Share on other sites More sharing options...
trq Posted October 10, 2006 Share Posted October 10, 2006 You would want to wrap a call to include within output buffering. Something like....[code=php:0]<?phperror_reporting(0);ob_start();include("timeTest.php");$info = ob_get_contents();ob_end_clean();$ctype="application/octet-stream";// disable HTML page caching on the PHP session levelsession_cache_limiter("nocache");header("Expires: 0");// HTTP/1.1// disable browser and proxy cacheheader("Cache-Control: no-store, no-cache, must-revalidate");header("Cache-Control: post-check=0, pre-check=0", false);// HTTP/1.0header("Content-Type: $ctype");header("Pragma: ");echo $info;?>[/code] Quote Link to comment Share on other sites More sharing options...
heartburn Posted October 11, 2006 Author Share Posted October 11, 2006 That's great, I will try it in the morning. Thanks for the reply. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.