下面是我的代码:
include('simple_html_dom.php');
$html = file_get_html('http://www.exampel.com');
foreach($html->find('item') as $article) {
$item['title'] = $article->find('title', 0)->innertext;
$item['description'] = $article->find('description', 0)->innertext;
$item['description2'] .= $item['title'] .' : '. $item['description'] .'<br>';
$articles[] = $item;
}
echo $item['description2'];
我用$item['description2'] .=
来组合$item['description']
的每个结果
echo工作,但我得到"Notice: Undefined index: description2"
有什么问题吗?
以及如何将$item['description']
的每个循环结果放到一个变量中。
php第一次尝试连接字符串时没有$item['description2']
include('simple_html_dom.php');
$html = file_get_html('http://www.exampel.com');
foreach($html->find('item') as $article) {
$item['title'] = $article->find('title', 0)->innertext;
$item['description'] = $article->find('description', 0)->innertext;
if (!isset($item['description2'])) {
$item['description2'] = '';
}
$item['description2'] .= $item['title'] .' : '. $item['description'] .'<br>';
$articles[] = $item;
}
echo $item['description2'];