PHP kôd:
class VM{
/**
* ViaMichelin.com City2Hash PHP Class
* @author Webarto.com
* @copyright 2010
* @website http://webarto.com/53/viamichelin-php-class
*/
public function generateLink($from, $to){
return '<a href="http://www.viamichelin.com/web/Itineraires?strStartLocid='.$this->getHash($from).'&strDestLocid='.$this->getHash($to).'">Click here to get route from '.ucwords($from).' to '.ucwords($to).'</a>';
}
private function getHash($city){
$city = urlencode($city);
//cURL 4-5x faster than file_get_contents()
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.viamichelin.com/vmw2/maf/dyn/controller/jseLocationFinder?strMerged=$city");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close ($ch);
//Return hash from data
preg_match('/gf : \"(.*?)\"/', $data, $bingo);
if(!empty($bingo[1])) return $bingo[1];
}
}
Pozivanjem funkcije...
PHP kôd:
$vm = new VM;
echo $vm->generateLink("beograd", "novi sad"); //from city, to city
Dobijemo...
<a href="http://www.viamichelin.com/web/Itineraires?strStartLocid=31NDIxOTMxMGNORFF1T0RBMU 56ST1jTWpBdU5EZzBNRFk9&strDestLocid=31NDIxZG0xMGNO RFV1TWpRM01qST1jTVRrdU9ESXlPRFE9">Click here to get route from Beograd to Novi Sad</a>
Odnosno
KLIK
Odnosno
Nadam se da će pomoći nekome.
Homepage:
http://webarto.com/53/viamichelin-php-class