mark107 Posted April 26, 2014 Share Posted April 26, 2014 Hi all, I need some help with my php script. I'm working on the script to parsing the time from my other script so I can convert the hours into format, example: the hours I parse is 1:00 AM so I can convert it to 20140427010000. Here is the list of format for 3 channels: 20140427010000 20140427013000 20140427020000 20140427023000 20140428063000 20140428070000 20140428103000 20140428133200 20140428170000 20140429120000 20140429123000 20140429130000 20140429133000 20140429140000 20140426210000 20140426220000 20140426230000 20140427000000 20140427003500 20140427013700 20140427023700 20140427070000 20140428000000 20140428013000 20140428050000 20140428060000 20140428070000 20140429000000 20140429030000 20140429060000 20140429063000 20140429070000 20140426210000 20140426220000 20140426223000 20140426230000 20140427000000 20140427010000 20140427013000 20140427020000 20140427030000 20140428000000 20140428010000 20140428020000 20140428030000 20140428040000 20140429000000 20140429010000 20140429020000 20140429030000 20140429040000 Here is the PHP: <?php ini_set('max_execution_time', 300); $errmsg_arr = array(); $errflag = false; include ('simple_html_dom.php'); function getState($string) { $ex = explode(" ",$string); return $ex[1]; } $xml .= '<?xml version="1.0" encoding="UTF-8" ?>'; $xml .= ' <tv generator-info-name="www.mysite.com/xmltv">'; $base1 = "http://www.mysite.com/get-listing.php"; $html = file_get_html($base1); $i = 0; foreach($html->find('p[id=links]') as $element) { $program_list[ $count ] = array(); $id_split = explode("?", $element->plaintext); $id_split = explode("&", $link_split[1]); $channels = explode("channels=",$id_split[0]); $channels = $channels[1]; $id = explode("id=",$id_split[1]); $id = $id[1]; //channels //$channel_test = $html->find('p[id=channels]', 10)->plaintext; //echo $channel_test; $program_list[$count]['channels'] = $channels; $program_list[$count]['id'] = $id; $channels_split = explode("?", $element->plaintext); $channels_split = explode("&", $channels_split[1]); $channel_id = explode("channels=",$channels_split[0]); $channel_id = $channel_id[1]; $my_id = explode("id=",$channels_split[1]); $my_id = $my_id[1]; $channel = urlencode($channel_id); $id_1 = urlencode($my_id); $html_two = file_get_html("http://www.mysite.com/get-listing.php?channels=" . $channel . "&id=" . $my_id); $time1 = $html_two->find('span[id=time1]',0)->plaintext; $time2 = $html_two->find('span[id=time2]',0)->plaintext; $time3 = $html_two->find('span[id=time3]',0)->plaintext; $time4 = $html_two->find('span[id=time4]',0)->plaintext; $time5 = $html_two->find('span[id=time5]',0)->plaintext; $time6 = $html_two->find('span[id=time6]',0)->plaintext; $time7 = $html_two->find('span[id=time7]',0)->plaintext; $time8 = $html_two->find('span[id=time8]',0)->plaintext; $time9 = $html_two->find('span[id=time9]',0)->plaintext; $time10 = $html_two->find('span[id=time10]',0)->plaintext; $time11 = $html_two->find('span[id=time11]',0)->plaintext; $time12 = $html_two->find('span[id=time12]',0)->plaintext; $time13 = $html_two->find('span[id=time13]',0)->plaintext; $time14 = $html_two->find('span[id=time14]',0)->plaintext; $array = array( $time1, $time2, $time3, $time4, $time5, $time6, $time7, $time8, $time9, $time10, $time11, $time12, $time13, $time14, ); // Save the output format $DATE_FORMAT_STRING = "YmdHis"; // GET the current STAGE $current_state = getState($array[0]); $offset = 0; foreach($array as $time) { // Get the item state. $this_state = getState($time); // check if we past a day? if($current_state == "PM" && $this_state == "AM") { $offset++; } $this_unix = strtotime($time) + (60 * 60 * 24 * $offset); echo date($DATE_FORMAT_STRING, $this_unix); echo "<br></br>"; $current_state = $this_state; } } ?> I want to know how do you get each of those format to output them in the xml start="" and end="" like this? <?xml version="1.0" encoding="UTF-8" ?> <tv generator-info-name="www.mysite.com/XML"> <programme channel='test start='20140427010000' stop='20140427013000'> <title lang="en"></title> <sub-title lang="en"></sub-title> <desc lang="en"> </desc> <category lang="en"></category> </programme> <programme channel='test start='20140427013000' stop='20140427020000'> <title lang="en"></title> <sub-title lang="en"></sub-title> <desc lang="en"> </desc> <category lang="en"></category> </programme> <programme channel='test start='20140427020000' stop='20140427023000'> <title lang="en"></title> <sub-title lang="en"></sub-title> <desc lang="en"> </desc> <category lang="en"></category> </programme> <programme channel='test start='20140427023000' stop='20140428063000'> <title lang="en"></title> <sub-title lang="en"></sub-title> <desc lang="en"> </desc> <category lang="en"></category> </programme> <programme channel='test start='20140428063000' stop='20140428070000'> <title lang="en"></title> <sub-title lang="en"></sub-title> <desc lang="en"> </desc> <category lang="en"></category> </programme> </tv> I tried to use the values, but I will get the wrong format and the format will get mess up if I use the values. Does anyone know how I can get the format for per channel using with the values if that is possible? Quote Link to comment https://forums.phpfreaks.com/topic/288022-how-to-get-the-format-using-the-values/ Share on other sites More sharing options...
mark107 Posted April 26, 2014 Author Share Posted April 26, 2014 I have got a problem with my PHP and I need your urgent help. I have the list of 3 urls where I'm sending the request to each url to get the hours so I will convert it to format. Example: I will get the hours of 7:30 AM, so I will convert them into this 20140426073000, for 9:30AM i will convert it to 20140426093000. For Url one input: 7:30 AM 9:30 AM For Url two input: 9:00 AM 11:00 AM For Url three input: 9:00 AM 10:00 AM In that way, when I send the request to each url to get the hours and converting the hours into format, I will get the three same input of format when I run through the loops. Here is the input: 20140426073000 20140426093000 20140426073000 20140426093000 20140426073000 20140426093000 It should be looks like this: 20140426073000 20140426093000 20140426009000 20140426011000 20140426090000 20140426100000 Here is the code: <?php ini_set('max_execution_time', 300); $errmsg_arr = array(); $errflag = false; include ('simple_html_dom.php'); function getState($string) { $ex = explode(" ",$string); return $ex[1]; } $xml .= '<?xml version="1.0" encoding="UTF-8" ?>'; $xml .= ' <tv generator-info-name="www.mysite.com/xmltv">'; $base1 = "http://www.mysite.com/get-listing.php"; $html = file_get_html($base1); $i = 0; $count = 0; foreach($html->find('p[id=links]') as $element) { $program_list[ $count ] = array(); $id_split = explode("?", $element->plaintext); $id_split = explode("&", $link_split[1]); $channels = explode("channels=",$id_split[0]); $channels = $channels[1]; $id = explode("id=",$id_split[1]); $id = $id[1]; //channels //$channel_test = $html->find('p[id=channels]', 10)->plaintext; //echo $channel_test; $program_list[$count]['channels'] = $channels; $program_list[$count]['id'] = $id; $channels_split = explode("?", $element->plaintext); $channels_split = explode("&", $channels_split[1]); $channel_id = explode("channels=",$channels_split[0]); $channel_id = $channel_id[1]; $my_id = explode("id=",$channels_split[1]); $my_id = $my_id[1]; $channel = urlencode($channel_id); $id_1 = urlencode($my_id); $html_two = file_get_html("http://www.mysite.com/get-listing.php?channels=" . $channel . "&id=" . $my_id); $time1 = $html_two->find('span[id=time1]',0)->plaintext; $time2 = $html_two->find('span[id=time2]',0)->plaintext; $time3 = $html_two->find('span[id=time3]',0)->plaintext; $array = array( $time1, $time2, $time3, ); // Save the output format $DATE_FORMAT_STRING = "YmdHis"; // GET the current STAGE $current_state = getState($array[0]); $offset = 0; foreach($array as $time) { // Get the item state. $this_state = getState($time); // check if we past a day? if($current_state == "PM" && $this_state == "AM") { $offset++; } $this_unix = strtotime($time) + (60 * 60 * 24 * $offset); $values[] = date($DATE_FORMAT_STRING, $this_unix); //echo date($DATE_FORMAT_STRING, $this_unix); //echo "<br></br>"; } echo $values[0]; echo "<br>"; echo $values[1]; echo "<br></br>"; $current_state = $this_state; } ?> When I tried to get the time for each url that I send request to convert to format, I will get the same input of format when I run through the loops. Do you know how I can get each different format when I send the request to each url? Quote Link to comment https://forums.phpfreaks.com/topic/288022-how-to-get-the-format-using-the-values/#findComment-1477406 Share on other sites More sharing options...
mac_gyver Posted April 26, 2014 Share Posted April 26, 2014 your two threads have been merged together. do not keep creating new threads for the same problem. Quote Link to comment https://forums.phpfreaks.com/topic/288022-how-to-get-the-format-using-the-values/#findComment-1477411 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.