I have a site with the collection of books; each book have a its own information page (like http://mybookscollection.com/book.php?iditem=2).
<html>
<body>
<div class="book">
<div id="author">Author</div>
<div id="title">Title</div>
<div id="date">Date</div>
</div>
</body>
</html>
I want to extract all books information and put this in a txt file like this.
1; Author1; Title1; Date1
2; Author2; Title2; Date2
3; Author3; Title3; Date3
To parse my html page I use "PHP Simple HTML DOM Parser" from http://simplehtmldom.sourceforge.net/
My php code is
<?php
// include HTML DOM Parser from http://simplehtmldom.sourceforge.net/
include ('simple_html_dom.php');
// make a loop for looking the first ten books
for ($i=1; $i<=10; $i++)
{
// look a book page by id
$url = 'http://mybookscollection.com/book.php?iditem='.$i;
$html = file_get_html($url);
// parse the htmls content to get a data
foreach($html->find('div[id=author]') as $element)
{$author = $element->plaintext;}
foreach($html->find('div[id=title]') as $element)
{$title = $element->src;}
foreach($html->find('div[id=date]') as $element)
{$date = $element->plaintext;}
// put all one book's data in the array "book"
$book = implode(";", array($i, $author, $title, $date));
// HERE NEED TO CREAT A NEW ARRAY "COLLECTION" WHERE PUT ALL "BOOK"'S ARRAY
//use echo to print data in the browser
//echo '<div>'. $book .'</div>';
//write a file with all data
$fp = fopen('result.txt', 'w');
// NORMALY HAVE TO PUT HERE "$COLLECTION" NOT JUST ONE "$BOOK"
fwrite($fp, $book);
fclose($fp);
}
?>
It works fine and I get all my data. My problem is that I can't put tougher (in the same array "collection") each book's array to print all books information in the same txt file. I know it's a noobie question about a two multidimensional array but I can't figure it out. Many thanks for your help!