有人能帮我吗。。。
我想要像一样的输出
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)
)
所有日期"2014年4月1日"都在$days数组中,[text]和[link]内容在foreach循环中生成。
我的代码是这样的:
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);
link.html就像这个
<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>
请尝试以下操作:
$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);