Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //podle názvu města
- print_r(getOdstavkyCez('Děčín'));
- //podle PSČ (5 číslic bez mezer)
- print_r(getOdstavkyCez('40502'));
- //podle názvu města/PSČ a ulice
- print_r(getOdstavkyCez('40502','Förstrova'));
- function getOdstavkyCez($mesto,$ulice=false) {
- if (preg_match('/^[0-9]{5}$/',$mesto)) {
- $search=array('mesto' => '*', 'psc' => $mesto);
- } else {
- $search=array('mesto' => $mesto);
- }
- echo $ulice;
- if($ulice) $search['ulice']=$ulice;
- $url = 'https://dip.cezdistribuce.cz/irj/portal/anonymous/rest-api?path=/vyhledaniOdstavek/nactiOdstavky';
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($search));
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- if($result=curl_exec($ch)) {
- return json_decode($result);
- }
- else return false;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement