Advertisement
Guest User

ČEZ Odstávky

a guest
Nov 29th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2. //podle názvu města
  3. print_r(getOdstavkyCez('Děčín'));
  4.  
  5. //podle PSČ (5 číslic bez mezer)
  6. print_r(getOdstavkyCez('40502'));
  7.  
  8. //podle názvu města/PSČ a ulice
  9. print_r(getOdstavkyCez('40502','Förstrova'));
  10.  
  11. function getOdstavkyCez($mesto,$ulice=false) {
  12.   if (preg_match('/^[0-9]{5}$/',$mesto)) {
  13.     $search=array('mesto' => '*', 'psc' => $mesto);    
  14.   } else {
  15.     $search=array('mesto' => $mesto);      
  16.   }
  17.   echo $ulice;
  18.   if($ulice) $search['ulice']=$ulice;
  19.   $url = 'https://dip.cezdistribuce.cz/irj/portal/anonymous/rest-api?path=/vyhledaniOdstavek/nactiOdstavky';
  20.   $ch = curl_init($url);
  21.   curl_setopt($ch, CURLOPT_POST, true);
  22.   curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($search));
  23.   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  24.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  25.   if($result=curl_exec($ch)) {
  26.     return json_decode($result);
  27.   }
  28.   else return false;
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement