문제

Can anyone please help me for this...

I want the output like

Array (
    [1st Apr 2014][0] => Array ([daylink] => 1st Apr 2014 [text] => Report of 1st Apr 2014 - View [link] => link1.html)
    [2nd Apr 2014][0] => Array ([daylink] => 2nd Apr 2014 [text] => Report of 2nd Apr 2014 - View [link] => link2.html)
    [3rd Apr 2014][0] => Array ([daylink] => 3rd Apr 2014 [text] => Report of 3rd Apr 2014 - View [link] => link2.html)
    [4th Apr 2014][0] => Array ([daylink] => 4th Apr 2014 [text] => Report of 4th Apr 2014 - View [link] => link2.html)
)

All the date "1st Apr 2014" is in an array $days and [text] and [link] content is generated in the foreach loop itself.

My code is like this:

include('simple_html_dom.php');

$html = file_get_html('Link.html');

$today_date = $month_name = date('jS M Y');

$monday = date('jS M Y',strtotime('last monday'));
$tuesday = date('jS M Y',strtotime('last tuesday'));
$wednesday = date('jS M Y',strtotime('last wednesday'));
$thursday = date('jS M Y',strtotime('last thursday'));

$days = array($monday, $tuesday, $wednesday, $thursday);

foreach ($days as $day) {

$tds = $html->find('table',1)->find('span');

$num = 0;
foreach($tds as $td){

    if (strpos($td->plaintext, $day) !== false){
            echo $day . "<br>";
            $next_td = $td->next_sibling();

            if (!empty($next_td)) 
            $linka = $next_td->find('a');
                foreach($linka as $elm) {
                $num = $elm->href;
                }

                //echo $td->plaintext. "<br />";
                //echo $num . "<br />";
            $day_url =  array($day => array(daylink => $day, text => $td->plaintext, link => $num));




         }


    }
}

print_r($day_url);

and link.html is like this

<table>
    <tbody>
        <tr class="c0">
            <td class="c11">
                <td class="c8">
                    <ul class="c2 lst-kix_h6z8amo254ry-0 start">
                        <li class="c1">
                            <span>1st Apr 2013 - </span>
                            <span>1st Apr 2014 - </span>
                            <span class="c6">
                                <a class="c4" href="/link.html">View</a>
                            </span>
                            <span>1st Apr 2015 - </span>
                        </li>
                    </ul>
                </td>
            </td>
        </tr>
    </tbody>
</table>
도움이 되었습니까?

해결책

Please try this:

$dayArray=array('1st Apr 2014','2nd Apr 2014','3rd Apr 2014','4th Apr 2014');
$resultArray=array();
$count=1;
foreach($dayArray as $value){
    $resultArray[$value][]=array(
                'daylink'   =>  $value,
                'text'      =>  'report for '.$value,
                'link'      =>  'link'.$count.'.html'
            );

    $count++;
}

print_r($resultArray);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top