<?php
unlink(PATH.'/view/tool/'.$Route->params->self.'/data.json');
$client = new \GuzzleHttp\Client(); 
$response = $client->request('GET', 'https://gamedistribution.com/rss-builder', ['verify' => false]);
// Preg match
preg_match('@id="ddlCategory"(.*?)</select>@si',$response->getBody(), $CategoryExp);
preg_match_all('@value="(.*?)"(.*?)>(.*?)</option>@si',$CategoryExp[0], $Category); 

preg_match('@id="ddlCollection"(.*?)</select>@si',$response->getBody(), $SortExp);
preg_match_all('@value="(.*?)"(.*?)>(.*?)</option>@si',$SortExp[0], $Sort); 

$Listings = [];
for ($i=0; $i <count($Category[0]) ; $i++) {   
	$Listings['category'][] = [
		'name'		=> trim($Category[3][$i]),
		'url'		=> str_replace('&category=', '',trim($Category[1][$i]))
	];  
}   
for ($ii=0; $ii <count($Sort[0]) ; $ii++) {   
	$Listings['sort'][] = [
			'name'		=> trim($Sort[3][$ii]),
			'url'		=> trim($Sort[1][$ii])
	];  
}   
$JsonData = json_encode($Listings,JSON_UNESCAPED_UNICODE); 
$fp = fopen(PATH.'/view/tool/'.$Route->params->self.'/data.json', 'w+');
fwrite($fp, $JsonData);
fclose($fp); 