Monday, November 23, 2009

Perl 定義ファイルの例と使い方

---定義ファイルの例
# Mysql DB Configure
DB_HOST = 'localhost'
DB_USER = 'test'
DB_PASSWORD = 'test1234'
DB_DATABASE = 'test'
----

#!/usr/bin/perl
open (CONF,"dbs.conf") || die "cannot open conf file!";
while () {
$_ =~ s/\#.*//g;
if ($_ =~ /'.*'/) {
/(\S+).*=.*\'(\S+)\'/;
${lc($1)} = $2;
}
}
close (CONF);

Wednesday, November 04, 2009

wget PHP

/*
$url = " http://192.168.1.1/test/test.php";
$www = new wget();
$but = $www->get($url,true,true, "aaa=1&www=2"); // パラメータでシングルコーテーションは'に変更する
echo $but;
*/

class wget{
const SAVE_COOKIE = "--save-cookies cookies.txt --keep-session-cookies";
const LOAD_COOKIE = "--load-cookies cookies.txt";
const OUT_FILE = "test11.text";

const DEV = " >/dev/null 2>&1 ";
const OP_TIME = "--timeout=60 --wait=5";
const SAVE_FILE = "--output-document=test11.text";
const TRIES = " -t 1 ";
const USERAGENT = '--user-agent="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"';


public function __construct(){

}
/*
post_data = "ssss=qqq&eee=1";
*/
public function get($url,$save_cookie=null,$load_cookie=null,$post_data=null){
if ($save_cookie==true){
$save_cookie = self::SAVE_COOKIE;
}else{
$save_cookie = "";
}
if ($load_cookie==true){
$load_cookie = self::LOAD_COOKIE;
}else{
$load_cookie = "";
}
if ($post_data!=null){
$post_data = "--post-data='".$post_data."'";
}

$com = "wget". self::TRIES ." $save_cookie $load_cookie ". self::OP_TIME." ". self::USERAGENT." ". $post_data." ". $url ." " .self::SAVE_FILE." " .self::DEV;
$foo = system($com,$output);
$buff = file_get_contents( self::OUT_FILE, true);
return $buff;

}
public function __destruct(){
}


}