<?php
class Proxy {
function GetPage() {
$ch = curl_init("http://www.proxy4free.com/page1.html");
$fp = fopen("unparsed_proxies.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
function ParseFile() {
if (file_exists("proxies.txt")){
unlink("proxies.txt");
}
$line_num = 0;
$data = file("unparsed_proxies.txt");
foreach ($data as $value) {
$line_num ++;
if (preg_match("/proxy_text/i", $value)) {
$ipline = $data[$line_num];
$ipline = str_replace("<td>", "", $ipline);
$ipline = str_replace(" ", "", $ipline);
$ip = str_replace("</td>\n", "", $ipline);
$portline = $data[$line_num+1];
$portline = str_replace("<td>", "", $portline);
$portline = str_replace(" ", "", $portline);
$port = str_replace("</td>", "", $portline);
$file = fopen('proxies.txt', 'a');
$text="$ip:$port";
if (preg_match("/copyright/i", $text)) {
$text = "";
}
fwrite($file, $text);
fclose($file);
}
}
if (file_exists("unparsed_proxies.txt")){
unlink("unparsed_proxies.txt");
}
}
function RandomProxy() {
$data = file("proxies.txt");
$linescount = count($data);
$randomline = rand(0, $linescount);
$randproxy = $data[$randomline];
$new_string=urlencode ($randproxy);
$new_string=ereg_replace("%0D", " ", $new_string);
$new_string=ereg_replace("%0A", " ", $new_string);
$new_string=urldecode ($new_string);
return $new_string;
}
}
?>