Question

here goes my code

$url = 'link.html'

$html = file_get_html($url);

$dayArray = array('28th Apr 2014', '29th Apr 2014' , '30th Apr 2014' ,'1st May 2014');

foreach($dayArray as $value){ 

$dayArrayvalue=strtotime($value);
$month_name=date("F",$dayArrayvalue);


foreach($html->find('table',1)->find('a') as $elm) {

if($elm->plaintext == $month_name){
    $month_links1= $elm->href;

//array_push($month_links, $month_links1);

$month_links[] = $month_links1;

}
else{
  $month_links[] = 0;
}

}
}

print_r( $month_links);

I want to store each month link in the aaray if the month name match with date of the month

in the link.html the second table contains the month with links

can any one help me ?

Was it helpful?

Solution

try this updated version, I am guessing what you want as you didn't clearly explain what your aim behind your code is.

$url = 'link.html'
$html = file_get_html($url);
//$dayArray = array('28th Apr 2014', '29th Apr 2014' , '30th Apr 2014' ,'1st May 2014');
$monthNameArray = array('April', 'May');
$month_links = array();

foreach($monthNameArray as $month_name){ 

    //$dayArrayvalue=strtotime($value);
    //$month_name=date("F",$dayArrayvalue);

    foreach($html->find('table',1)->find('a') as $elm) {

        if(strcasecmp($elm->plaintext,$month_name)==0){
            array_push($month_links, $elm->href);
        }
        //else{
        //this will add a 0 to the array if there is no match. I don't think this is what you want, so just remove it if not needed
       //      array_push($month_links, '0');
       // }
    }
}

print_r( $month_links);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top