<?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;
}

			//$cmd = "http://www.upcitemdb.com/query?s=Codenames&type=2";
			
			//http://www.upcitemdb.com/query?s=Codename%3A%20Icarus&type=2
			
			// http://www.upcitemdb.com/upc/888462323772
			
			//https://www.webmasterworld.com/php/4852693.htm  +++++++
			
			//upcitemdb.com
			//$html = file_get_html($cmd);
			//echo $html;

			
	/*		
			$html = file_get_html($cmd);
			foreach ($html->find('li.blue') as $li)
			{
				echo $li->title . '<br>';
			}
	*/		
			
			
/*			
							<ul>
							<li><a href="/upc/717356247040" class="img" title="UPC 717356247040 product info">
							<img itemprop="image" src="/barcode/ean13/0717356247040.png" width=100  alt="EAN-13 Barcode of UPC 717356247040"></a>
							<a href="/upc/717356247040" class="img_prod" title="UPC 717356247040 product info">
							<img src="https://i.ebayimg.com/00/s/MTAwMFgxMDAw/z/LwgAAOSwc2FaNi6K/$_12.JPG?set_id=880000500F"></a>
							<div class="rImage">
							<a href="/upc/717356247040" title="UPC 717356247040 product info">717356247040</a>
							<p>Codenames</p>
							</div>
							</li>
							
									
							<li><a href="/upc/727523290489" class="img" title="UPC 727523290489 product info">
							<img itemprop="image" src="/barcode/ean13/0727523290489.png" width=100  alt="EAN-13 Barcode of UPC 727523290489"></a>
							<a href="/upc/727523290489" class="img_prod" title="UPC 727523290489 product info">
							<img src="http://ecx.images-amazon.com/images/I/51oouy-fkyL._SL160_.jpg"></a>
							<div class="rImage">
							<a href="/upc/727523290489" title="UPC 727523290489 product info">727523290489</a>
							<p>Codenames Party Word Game Adult Cards Team Words Against Morality Humanity Four Pack Volume Family Fun Trivia Gamewright educational school English vocabulary associative thinking brain Kids</p>
							</div>
							</li>
							
							
							<li><a href="/upc/603205837954" class="img" title="UPC 603205837954 product info"><img itemprop="image" src="/barcode/ean13/0603205837954.png" width=100  alt="EAN-13 Barcode of UPC 603205837954"></a><a href="/upc/603205837954" class="img_prod" title="UPC 603205837954 product info"><img src="http://i.ebayimg.com/00/s/NzU3WDgwMA==/z/zg8AAOSw7cxZoe1K/$_12.JPG?set_id=880000500F"></a><div class="rImage"><a href="/upc/603205837954" title="UPC 603205837954 product info">603205837954</a><p>Codenames , Two Days Shipping</p></div></li><li><a href="/upc/841887050975" class="img" title="UPC 841887050975 product info"><img itemprop="image" src="/barcode/ean13/0841887050975.png" width=100  alt="EAN-13 Barcode of UPC 841887050975"></a><a href="/upc/841887050975" class="img_prod" title="UPC 841887050975 product info"><img src="http://dynamic.indigoimages.ca/dvd/841887050975.jpg?width=200&maxheight=200"></a><div class="rImage"><a href="/upc/841887050975" title="UPC 841887050975 product info">841887050975</a><p>Cyberchase - Codename Icky</p></div></li><li><a href="/upc/20286154952" class="img" title="UPC 020286154952 product info"><img itemprop="image" src="/barcode/ean13/0020286154952.png" width=100  alt="EAN-13 Barcode of UPC 020286154952"></a><a href="/upc/20286154952" class="img_prod" title="UPC 020286154952 product info"><img src="http://dynamic.indigoimages.ca/music/020286154952.jpg?width=200&maxheight=200"></a><div class="rImage"><a href="/upc/20286154952" title="UPC 020286154952 product info">020286154952</a><p>Codename: Rondo</p></div></li><li><a href="/upc/53939679120" class="img" title="UPC 053939679120 product info"><img itemprop="image" src="/barcode/ean13/0053939679120.png" width=100  alt="EAN-13 Barcode of UPC 053939679120"></a><a href="/upc/53939679120" class="img_prod" title="UPC 053939679120 product info"><img src="http://dynamic.indigoimages.ca/dvd/053939679120.jpg?width=200&maxheight=200"></a><div class="rImage"><a href="/upc/53939679120" title="UPC 053939679120 product info">053939679120</a><p>Codename:  Kids Next Door - Super Hugest  Missions:  File One</p></div></li><li><a href="/upc/710425278778" class="img" title="UPC 710425278778 product info"><img itemprop="image" src="/barcode/ean13/0710425278778.png" width=100  alt="EAN-13 Barcode of UPC 710425278778"></a><a href="/upc/710425278778" class="img_prod" title="UPC 710425278778 product info"><img src="http://gamefly.gameflycdn.com/images/Games/p/116665p.jpg"></a><div class="rImage"><a href="/upc/710425278778" title="UPC 710425278778 product info">710425278778</a><p>Codename: Kids Next Door - Operation Videogame - Pre-Played</p></div></li>
 */  
			
			
			// Create a DOM object
			//$dom = new simple_html_dom();
			// Load HTML from a string
			//$dom->load($cmd);
			//print_r($dom);
			
			//https://github.com/paquettg/php-html-parser
			
			// http://petit-dev.com/parsez-le-contenu-dun-site-avec-simple-html-dom-parser/
			
			// https://stackoverflow.com/questions/41171500/php-dom-how-to-parse-li-tag-with-specific-class-and-print-its-title-attrib
			
			http://boardgamegeek.com/xmlapi/search?search=frika
http://boardgamegeek.com/xmlapi/search?search=scythe
https://www.boardgamegeek.com/xmlapi2
https://www.codeproject.com/Articles/156402/Android-Generating-an-EAN-Barcode

https://github.com/coolbong/android-barcode/blob/master/src/com/coolbong/barcodegenerator/BarCodeActivity.java
			
	
			echo "/*****************  You Know product name, find Bar code **********************/";	
			echo "<br>";

			$cmd = "http://www.upcitemdb.com/query?s=Codenames&type=2";
			$html = file_get_html($cmd);
			$UPC_tab = array();
			foreach ($html->find('li') as $li) 
			{
				$UPC_tab[] = $li->plaintext;
			}
					
			for ($i = 7; $i <= sizeof($UPC_tab) - 8 ; $i++) 
			{
				if(1 === preg_match('~[0-9]~', $UPC_tab[$i])) // echo  strlen($UPC_tab[$i])
				{
					echo "0" .substr($UPC_tab[$i], 0, 12) . "   -----------   " . substr($UPC_tab[$i], 12, strlen ( $UPC_tab[$i] )); 
					echo "<br>";
				}	
			}
			
			//echo "<pre>";
			//print_r($UPC_tab);
		
			
			echo "/************* You Know product name , find UPC (EAN13) **************************/";	
			echo "<br>";
			
			$cmd = "http://www.upcitemdb.com/upc/888462323772";
			$html = file_get_html($cmd);
			$infos_products = array();
			foreach ($html->find('li') as $li) 
			{
				$infos_products[] = $li->plaintext;
			}
			
			
			for ($i = 7; $i <= sizeof($infos_products) - 8 ; $i++) 
			{
				echo $infos_products[$i];
				echo "<br>";
			}
			
			//echo "<pre>";
			//print_r($infos_products);
			
			
			
						
			
			echo $html->find('li', 35)->plaintext;
			
			
			
				//$myDiv = $html->find('div'); // wherever your the div you're ending up with is
			//$children = $myDiv->children;
			//echo $children;
			
			# get all elements with class="foo"
			//$collection = $html->find('.container');
			//echo "<pre>";
			//print_r($toto);
			
	
			
?>