TEXT   8

header

Guest on 25th November 2021 08:39:56 AM

  1. <?php
  2. header("Content-type: application/json; charset=utf-8");
  3. $request = @$_POST["keyword"];
  4. error_reporting(0);
  5. if(isset($request)) {
  6.  
  7.     $curl = curl_init();
  8.     if(isset($_POST['page'])) {
  9.         $url = 'https://www.dastelefonbuch.de/Suche/'.urlencode($request).'/'.$_POST["page"];
  10.     } else {
  11.         $url = 'https://www.dastelefonbuch.de/Suche/'.urlencode($request);
  12.     }
  13.     curl_setopt_array($curl, array(
  14.       CURLOPT_URL => $url,
  15.       CURLOPT_RETURNTRANSFER => true,
  16.       CURLOPT_ENCODING => '',
  17.       CURLOPT_MAXREDIRS => 10,
  18.       CURLOPT_TIMEOUT => 0,
  19.       CURLOPT_FOLLOWLOCATION => true,
  20.       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  21.       CURLOPT_CUSTOMREQUEST => 'GET',
  22.     ));
  23.  
  24.     $response = curl_exec($curl);
  25.  
  26.     curl_close($curl);
  27.  
  28.     $htmlString = $response;
  29.  
  30.     $dom = new DOMDocument;
  31.  
  32.     @$dom->loadHTML('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'. $htmlString);
  33.  
  34.     $xp = new DOMXpath($dom);
  35.  
  36.     $figures = array();
  37.  
  38.     $figureElements = $xp->query('//div[contains(@class,"entry")]');
  39.  
  40.     $figureCount = 0;
  41.     function titler($str) {
  42.         $res = str_replace( array('\n',
  43.         ), '', $str);
  44.  
  45.         return trim(preg_replace('/\s\s+/', ' ', $res));
  46.     }
  47.     function RemoveSpecialChar($str) {
  48.         $res = str_replace( array('\n',
  49.         ' ' , '.', '-' ), '', $str);
  50.         $resp = preg_replace('/[^A-Za-z0-9\-]/', '', $res);
  51.         return "49".mb_substr($resp, 1, 11);
  52.     }
  53.  
  54.     foreach ($figureElements as $figureElement) {
  55.         $figures[$figureCount]["title"] = titler($xp->query('//span[contains(@itemprop,"name")]', $figureElement)->item($figureCount)->nodeValue);
  56.         $figures[$figureCount]["branch"] = titler($xp->query('//div[contains(@class,"category")]', $figureElement)->item($figureCount)->nodeValue);
  57.         $figures[$figureCount]["phone"] = trim(preg_replace('/\s\s+/', ' ', RemoveSpecialChar($xp->query('//span[contains(@class,"nr")]', $figureElement)->item($figureCount)->nodeValue)));
  58.         if($figures[$figureCount]["phone"] === "49") {
  59.             unset($figures[$figureCount]);
  60.         }
  61.         $figureCount++;
  62.     }
  63.  
  64.     echo json_encode($figures, JSON_UNESCAPED_UNICODE);
  65. }
  66. ?>

Raw Paste


Login or Register to edit or fork this paste. It's free.