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

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

$Listings = [];
for ($i=0; $i <count($Category[0]) ; $i++) {   
	$Listings['category'][] = [
		'name'		=> trim($Category[2][$i]),
		'url'		=> str_replace('&category=', '',trim($Category[1][$i]))
	];  
}   
for ($ii=0; $ii <count($Sort[0]) ; $ii++) {   
	$Listings['sort'][] = [
			'name'		=> trim($Sort[2][$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);