1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
| <?php
function fetchURL( $url )
{
$url_parsed = parse_url($url);
$host = $url_parsed["host"];
$port = $url_parsed["port"];
if ($port==0)
{
$port = 80;
}
$path = $url_parsed["path"];
if ($url_parsed["query"] != "")
{
$path .= "?".$url_parsed["query"];
}
$out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
fwrite($fp, $out);
$body = false;
while (!feof($fp))
{
$s = fgets($fp, 1024);
if($body)
{
$in .= $s;
}
if($s=="\r\n")
{
$body = true;
}
}
fclose($fp);
return $in;
}
function replaceScript($str)
{
$str=strtoupper($str);
while(strpos($str,'<SCRIPT')>0)
{
$start=strpos($str,'<SCRIPT');
$end=strpos($str,'</SCRIPT>');
$str=substr_replace($str,'',$start,$end-$start+10);
}
return $str;
}
function replaceHeader($str)
{
$str=strtoupper($str);
$start=strpos($str,'<HEAD>');
$end=strpos($str,'</HEAD>');
$str=substr_replace($str,'',$start,$end-$start+8);
return $str;
}
function replaceBody($str)
{
$str=strtoupper($str);
$start=strpos($str,'<BODY');
$end=strpos($str,'>',$start+1);
$str=substr_replace($str,'',$start,$end-$start+1);
$start=strpos($str,'</BODY>');
$str=substr_replace($str,'',$start,7);
return $str;
}
$str=fetchURL('http://www.bnb.bg/bnb/rates.nsf/vWebRatesByMonthBG/');
$str=replaceAHREF($str);
$str=replaceScript($str);
$str=replaceHeader($str);
$str=replaceBody($str);
print($str); |