Ninjakreborn Posted January 30, 2007 Share Posted January 30, 2007 [code]<?php// Build an array with all the channel names.$channels = array ("I11187", "I11829", "I11269", "I11768", "I11993", "I19556", "I11490", "I11479", "I11959", "I23319", "I18774", "I11287", "I12553", "I24634", "I23324", "I22564", "I23327", "I23328", "I23329", "I10240", "I10244", "I10241", "I18429", "I16585", "I24553", "I10243", "I10021", "I12852", "I16374", "I10142", "I10145", "I10139", "I10161", "I10162", "I10035", "I10057", "I10051", "I10153", "I11097", "I11163", "I11164", "I11207", "I10149", "I10989", "I14321", "I14909", "I10918", "I16409", "I45654", "I10179", "I12444", "I16485", "I12410", "I14899", "I14776", "I16011", "I20789", "I10986", "I16361", "I10138", "I11218", "I44228", "I11180", "I16331", "I11150", "I16615", "I18327", "I16617", "I16618", "I18284", "I16616", "I18544", "I18179", "I11158", "I14902", "I14771", "I12574", "I26784", "I10093", "I12131", "I10171", "I11006", "I16123", "I30103", "I21450", "I19059", "I18332", "I25354", "I31634", "I19283", "I18644", "I21852", "I21063", "I24935", "I24248", "I29323", "I28452", "I12324", "I16345", "I10239", "I11118", "I15377", "I27773", "I19247", "I18715", "I19979", "I25238"); // Build the file name's dynamically based on the above file names.// register empty array to hold the upcoming information$files = array();// run through all the channels, assining there full file names into an arrayforeach ($channels as $k) { $files[] = $k . ".labs.zap2it.com.xml"; // assign each file name into the files array}// attempt to create an xml parserif (!$parser = xml_parser_create()) { exit("There was a problem creating the parser");}// Functions To go into the element handlers, later on// variables to pass to user functions$currentdate = date();$showstarttime = "";$showstoptime = "";$tag = "<programme></programme>";$attributes = "@start, @stop, <title>, </title>";// function to start searchingfunction starttag($parser, $tag, $attributes) { }// function to end searchingfunction endtag($parser, $name) {}// function to take data from tagsfunction tagdata($parser, $data) { }xml_set_element_handler($parser, starttag(), endtag());xml_set_character_data_handler($xmlparser, tagdata());// use the file array created earlier to get to work// create an array to hold information on all the currently playing shows// from all the xml file's$nowplaying = array();foreach ($files as $k => $v) { // run through all the file's if (!$open = fopen($v, "r")) { // opening them // we can't do anything if any file's didn't open, because we don't have all the // necessary data, so kill the script exit("File could not be opened"); } while ($data = fread($open, 4096)){ if (!xml_parse($xmlparser, $data, feof($open))) { $reason = xml_error_string(xml_get_error_code($xmlparser)); $reason .= xml_get_current_line_number($xmlparser); die($reason); } }}// close foreach ?>[/code]Ok, I went through about 8 tutorials, and got somethign together.I worked this up, and ran into a lot of error's. I checked some references, and did some fixes, and removed a lot of the errors."I have another post open on misc about the date, I have to work that in after I get it doing the basics".I went over the tutorial on w3schools, and other places about xml/xsl and after thinking, because of WHAT I am wanting to do here, it's best to parse the file's with php, and return the results.since I have to get an updated copy everytime someone comes.Each channel is in a sepearet page, here is some example coding, that a channel might contain[code] <programme start="20070129140000 -0500" stop="20070129150000 -0500" channel="I44228.labs.zap2it.com"> <title lang="en">mtvU Video Hour</title> <category lang="en">Music</category> <category lang="en">Series</category> <episode-num system="dd_progid">SH684893.0000</episode-num> </programme> <programme start="20070129150000 -0500" stop="20070129160000 -0500" channel="I44228.labs.zap2it.com"> <title lang="en">mtvU Video Hour</title> <category lang="en">Music</category> <category lang="en">Series</category> <episode-num system="dd_progid">SH684893.0000</episode-num> </programme> <programme start="20070129160000 -0500" stop="20070129170000 -0500" channel="I44228.labs.zap2it.com"> <title lang="en">BFOC Student Film of the Week</title> <sub-title lang="en">Urban Shogun</sub-title> <date>20070126</date> <category lang="en">Art</category> <category lang="en">Limited Series</category> <episode-num system="dd_progid">EP895481.0001</episode-num> <episode-num system="onscreen">101</episode-num> </programme>[/code]I have to look at each file. Inside each file I have to look at all the contents of each pair of<programme> tag's. I have to check the start time and stop time doing this calculationif the start time is less than the current time, AND the stop time is greater than the current time, then pull the title out, and save it in an array (I guess I will call title).I need it to do that, for all of them, so I can get a list of 1 programme (the one playing now) for each and every channel.I know my current script has a long way's to go.However when I first did it, I ran into many errors.I am down to there.[quote]Warning: Wrong parameter count for date() in /home/wiltm/www/test/nowplaying.php on line 123Warning: Missing argument 1 for starttag() in /home/wiltm/www/test/nowplaying.php on line 129Warning: Missing argument 2 for starttag() in /home/wiltm/www/test/nowplaying.php on line 129Warning: Missing argument 3 for starttag() in /home/wiltm/www/test/nowplaying.php on line 129Warning: Missing argument 1 for endtag() in /home/wiltm/www/test/nowplaying.php on line 133Warning: Missing argument 2 for endtag() in /home/wiltm/www/test/nowplaying.php on line 133Warning: Missing argument 1 for tagdata() in /home/wiltm/www/test/nowplaying.php on line 137Warning: Missing argument 2 for tagdata() in /home/wiltm/www/test/nowplaying.php on line 137Warning: xml_set_character_data_handler(): supplied argument is not a valid XML Parser resource in /home/wiltm/www/test/nowplaying.php on line 142Warning: xml_parse(): supplied argument is not a valid XML Parser resource in /home/wiltm/www/test/nowplaying.php on line 155Warning: xml_get_error_code(): supplied argument is not a valid XML Parser resource in /home/wiltm/www/test/nowplaying.php on line 156Warning: xml_get_current_line_number(): supplied argument is not a valid XML Parser resource in /home/wiltm/www/test/nowplaying.php on line 157[/quote]I have done a lot of legwork, before bringing this here, I didn't want to just come here, and dump a bunch of problems, so I ahve fixed what I can. Tutorials are good, I am about to also sign up (today) for the orielly bookshelve again. IN hte meantime I have done all the tutorials I could find, referencing the manual, as much as I could. Is there another tutorial I could look over (or 2) I may not have used, so I can try and refine my code more.Or pointers on how to get this going in the right direction for what I am going to do. Quote Link to comment https://forums.phpfreaks.com/topic/36382-parsing-xml-files-with-php/ Share on other sites More sharing options...
Ninjakreborn Posted January 30, 2007 Author Share Posted January 30, 2007 Still having loads of problems.I have ran out of xml parsing tutorials, and read the manual dry of each function.Any input at this point is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/36382-parsing-xml-files-with-php/#findComment-173106 Share on other sites More sharing options...
boo_lolly Posted January 30, 2007 Share Posted January 30, 2007 [quote]Warning: Wrong parameter count for date() in /home/wiltm/www/test/nowplaying.php on line 123[/quote] may be that the date is an intiger, and not a string?and just as a side note, i don't think it's recommended to use hyphens ( - ) in your xml tags. Quote Link to comment https://forums.phpfreaks.com/topic/36382-parsing-xml-files-with-php/#findComment-173137 Share on other sites More sharing options...
boo_lolly Posted January 30, 2007 Share Posted January 30, 2007 i found these links that may help:http://w3schools.com/php/php_xml_simplexml.asphttp://w3schools.com/php/php_xml_parser_expat.asp Quote Link to comment https://forums.phpfreaks.com/topic/36382-parsing-xml-files-with-php/#findComment-173166 Share on other sites More sharing options...
Ninjakreborn Posted January 30, 2007 Author Share Posted January 30, 2007 Yes, I basically need to run a foreach through the xml file's (each one) and pull the now playing, I can't figure out how to do that, using the expat library, I have been working on it end of last week, and this week. Quote Link to comment https://forums.phpfreaks.com/topic/36382-parsing-xml-files-with-php/#findComment-173174 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.