how to convert each format into array

Discussion in 'PHP' started by mark103, Apr 27, 2014.

  1. #1
    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
    
    Code (markup):
    For Url two input:

    
    9:00 AM
    11:00 AM
    
    Code (markup):
    For Url three input:

    
    9:00 AM
    10:00 AM
    
    Code (markup):
    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:

    
    2014042607300020140426093000
    
    2014042607300020140426093000
    
    2014042607300020140426093000
    
    Code (markup):

    It should be looks like this:

    
    
    2014042607300020140426093000
    
    2014042600900020140426011000
    
    2014042609000020140426100000
    
    
    Code (markup):

    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 .= '
    <tvgenerator-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;
    }
    ?>
    
    Code (markup):
    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 to covert the time into format?
     
    mark103, Apr 27, 2014 IP
  2. salmanshafiq

    salmanshafiq Well-Known Member

    Messages:
    260
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    128
    #2
    Can you please add
    $values[]=array();
    Code (markup):
    After
    foreach($array as $time)
    {
    Code (markup):
    Please try.....
     
    salmanshafiq, Apr 28, 2014 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,897
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #3
    Can you post just the code that handles the data. All that extra xml stuff just confuses the issue. In your first post you give 3 different inputs (but they're the same format) and then you start talking about inputs again which are long date strings.
     
    sarahk, Apr 29, 2014 IP