functions-TelekomRs_White_Pages.php

lgaetz, 12/03/2010 05:34 am

Download (1.5 KB)

 
1
<?php
2
3
function cisf_find_area ($area_array, $full_number)
4
{
5
        foreach ($area_array as $area => $area_code) {
6
                if(substr($full_number,0,strlen($area_code))==$area_code) {
7
                        return array('area'=>$area,'area_code'=>$area_code,'number'=>substr($full_number,strlen($area_code)));
8
                }
9
        }
10
        return false;
11
}
12
13
function cisf_do_post_request($url,$post_data=false,$referrer = '',$cookie_file = false,$user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 ( .NET CLR 3.5.30729)") {
14
15
        $ch = curl_init();
16
        if($referrer){
17
                curl_setopt ($ch, CURLOPT_REFERER, $referrer);
18
        }
19
        curl_setopt ($ch, CURLOPT_URL, $url);
20
        curl_setopt($ch, CURLOPT_VERBOSE, 1); 
21
        curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
22
        curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
23
        curl_setopt ($ch, CURLOPT_HEADER, 1);
24
        if($cookie_file){
25
                curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie_file);
26
                curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie_file);
27
        }
28
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
29
        curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
30
        if($post_data){
31
                curl_setopt ($ch, CURLOPT_POST, 1); // set POST method
32
                curl_setopt ($ch, CURLOPT_POSTFIELDS, cisf_url_encode_array($post_data)); // add POST fields
33
        }
34
        $result = curl_exec ($ch);
35
        curl_close ($ch);
36
        return $result;
37
}
38
39
function cisf_url_encode_array($arr){
40
        $string = "";
41
        foreach ($arr as $key => $value) {
42
                $string .= $key . "=" . urlencode($value) . "&";
43
        }
44
        trim($string,"&");
45
        return $string;
46
}
47
48
?>
49