0

here is my code :

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']; 

i use $item['description2'] .= to combine foreach result of $item['description']

echo worked but i got "Notice: Undefined index: description2"

What is the problem?

and how to put each of the loop result of $item['description'] to one variable.?

1 Answer 1

1

There is no $item['description2'] the first time php try to concat the string.

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']; 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot buddy;

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.