在cmd窗口中set设置的环境变量为临时变量,如:
set PATH=%PATH%;D:\Program Files\
使用setx设置为永久环境变量:
setx PATH "%PATH%;D:\Program Files\"
发布时间:November 17, 2014 // 分类:Windows // No Comments
在cmd窗口中set设置的环境变量为临时变量,如:
set PATH=%PATH%;D:\Program Files\
使用setx设置为永久环境变量:
setx PATH "%PATH%;D:\Program Files\"
发布时间:November 16, 2014 // 分类:PHP // No Comments
发送或保存Cookie:
$ch = curl_init();
$url = 'https://www.haiyun.me/';
$cookiefile = '/tmp/cookie.txt';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); //保存cookie到此文件
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); //发送请求时从此文件获取cookie
curl_setopt($ch, CURLOPT_COOKIE, 'user=user; pass=pass'); //单独设置请求cookie
$content = curl_exec($ch);
curl_close($ch);
解析服务器设置的cookie并保存为变量:
$ch = curl_init('https://www.haiyun.me/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//输出返回head
curl_setopt($ch, CURLOPT_HEADER, 1);
$res = curl_exec($ch);
//切分内容和head
list($header, $body) = explode("\r\n\r\n", $res);
preg_match('/^Set-Cookie:\s*([^;]*)/mi', $header, $match);
parse_str($match[1], $cookies);
print_r($cookies);
从curl保存的cookie文件中解析cookie,文件格式见:http://www.cookiecentral.com/faq/#3.5
domain - The domain that created AND that can read the variable.
flag - A TRUE/FALSE value indicating if all machines within a given domain can access the variable. This value is set automatically by the browser, depending on the value you set for domain.
path - The path within the domain that the variable is valid for.
secure - A TRUE/FALSE value indicating if a secure connection with the domain is needed to access the variable.
expiration - The UNIX time that the variable will expire on. UNIX time is defined as the number of seconds since Jan 1, 1970 00:00:00 GMT.
name - The name of the variable.
value - The value of the variable.
<?php
$lines = file('/tmp/404344922.cookie');
foreach($lines as $line) {
if($line[0] != '#' && substr_count($line, "\t") == 6) {
$tokens = explode("\t", $line);
$tokens = array_map('trim', $tokens);
$cookies[$tokens[5]] = $tokens[6];
}
}
print_r($cookies);
设置保存cookie至文件:
<?php
$file = fopen("/tmp/reg.cookie", "a");
$domain = '.haiyun.me';
$flag = 'TRUE';
$path = '/';
$secure = 'FALSE';
$expiration = 0;
$key = 'key';
$value = 'value';
$cookie = "$domain\t$flag\t$path\t$secure\t$expiration\t$key\t$value\n";
fwrite($file, $cookie);
fclose($file);
发布时间:November 13, 2014 // 分类:Firefox // No Comments
网上有3种版本的Mason的重定向写法:
原版重定向仅能普通字符替换,正则要使用脚本:
<mason>
Charset=utf8
Author=ShuangYa
Created=2014/06/13
Updated=
name=Google Lib Redirector
version=1.0
Website=
Comment=
Description=Google Lib Redirector
Usage=
Url=^http[s]{0,1}://(.*?)googleapis\.com/(.*?)$
</mason>
<parts>
part1=.@@@L3
</parts>
<part1>
function _masonRedirect(spec){
return spec.replace(/^https/,'http').replace('googleapis.com','useso.com');
}
</part1>
紫云飞修改版使用:
http://function(url){return url.replace("aaa","bbb");}
水鑫日修改版使用:
http://>>aaa>>bbb #普通字符替换
http://>*aaa(.*)>*bbb$1 #正则替换
发布时间:November 9, 2014 // 分类:PHP,Typecho // 1 Comment
由于SQL正则替换不支持反向引用使用PHP读取替换并重新写入数据库:
<?php
$db = 'typecho';
$user = 'root';
$pass = 'password';
try {
$dbo = new PDO('mysql:host=localhost;dbname='.$db, $user, $pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8';"));
} catch (PDOException $e) {
$error = $e->getMessage();
die("PDO Execute Error : ".$error."\n");
}
$dbo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT cid,text FROM typecho_contents";
$stmt = $dbo->query($sql);
//$result = $stmt->fetch(PDO::FETCH_ASSOC);
//var_dump($result);
while (list($cid,$text)=$stmt->fetch(PDO::FETCH_NUM)){
echo $cid."\n";
$pattern = "/<code\s+?lang=[\'\"](\w+?)[\'\"]>/i";
//preg_match($pattern, $text, $matches);
//print_r($matches);
$text = preg_replace($pattern, "```\$1", $text);
$text = preg_replace('/<code>/', "```", $text);
$text = preg_replace('/<\/code>/', "```", $text);
$text = preg_replace('/^/', '<!--markdown-->', $text);
$st = $dbo->prepare("UPDATE typecho_contents set `text` = ? where cid = ?");
$st->bindParam(1, $text);
$st->bindParam(2, $cid);
$st->execute();
}