<?php

include('simple_html_dom.php');

function downloadURL($URL) 
{
	if(!function_exists('curl_init')) 
	{
		die ("Curl PHP package not installedn");
	}

 
	//*Initializing CURL*/
	$curlHandle = curl_init();

	//*The URL to be downloaded is set*/
	curl_setopt($curlHandle, CURLOPT_URL, $URL);

	//*Now execute the CURL, download the URL specified*/
	$response = curl_exec($curlHandle);
	return $response;
}

//echo downloadURL("http://www.google.com/");


$ch = curl_init("http://www.analog-design.net");

$cmd = "http://www.upcitemdb.com/query?s=Codenames&type=2";

//$ch = curl_init($cmd);



curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);

$html = file_get_html($cmd);

//https://sourceforge.net/projects/simplehtmldom/files/

//$json = json_decode($content, true);
//print_r($json);
//echo $content;


// Retrieve all images and print their SRCs

$tab_images = [];

foreach($html->find('img') as $e)
{
    echo $e->src . '<br>';
	$tab_images[] = $e->src;

}

	echo "<pre>";
	print_r($tab_images);

//	foreach($html->find('li') as $e)
//    echo $e->src . '<br>';
	
	
	//$elm->tag=='li'
	
	//$first_level_items = $html->find( '.container', 0)->children();
	//echo $first_level_items;
	
	echo "plouf";
	
	// Find the DIV tag with an id of "myId"
foreach($html->find('container') as $e)
    echo $e->innertext . '<br>';
	
//foreach ( $first_level_items as $item ) {
//    ... do stuff ...
//}
	
	
	
echo "/*****************  TRACE **********************/";	
	foreach ($html->find('li') as $li) {
    echo $li->plaintext . '<br>';
}
echo "/***************************************/";	

/*
	
$out = "patrice";

$fp = fopen('data.txt', 'w');
fwrite($fp, $out);
fclose($fp);

	$data = $html->find('li');
	
	echo "****************************************************";
	/*
	foreach ( $data as $item ) 
	{
		 echo $item->plaintext ."   "  .$item->find('img')->src . '<br>';
	}*/
	
	//Pour récupérer tous les liens présents dans un « h1″ : $collection = $html->find('h1 a');
//	$collection = $html->find('li img');
	
	//$coll = $html->find('li', 2);
	//$coll->parent;
	//$result->children(0);
	//print_r($result);
/*	
	
	foreach($html->find('li a') as $article) {
     $item['images']     = $article->src;
     $item['details']    = $article->plaintext;
    $articles[] = $item;
}
echo "<pre>";
print_r($articles); 
	

	
/*********************************************************************	
	
foreach($html->find('ul') as $ul)
{
       foreach($ul->find('li') as $li)
       {
             // do something...
       }
}

foreach($html->find('a') as $element)
echo $element->href . '<br>';
	
	
	$tab_titles = [];
	foreach($html->find('.rImage') as $post) 
	{
		//$item['title']   = $post->plaintext;
		echo $post->plaintext .'<br>';
		$tab_titles[] = $post->plaintext;
	}
	
	print_r($tab_titles);
	
*///////////////////////////////////////////////////////////////////////
  

?>