写了一个shell脚本 对数据库中每个表进行备份 这样可以方便的在表中进行筛选
bak_db_table.sh
————————————————————–
# bak_db_table.sh db db_host db_user db_passwd > log.txt
# by fallseir at 20081010
if [ $1 ] # 如果没有参数
then
echo database $1;
else
echo ‘backup database tables to gzip files
sh bak_db_table.sh db [db_host] [db_user] [db_passwd]
‘; exit;
fi
# 参数赋值
[ $1 ] && db=$1
[ $2 ] && dbh=$2
[ $3 ] && dbu=$3
[ $4 ] && dbp=$4
# 配置数据库参数
[ $dbh ] && dbh=”-h”$dbh
[ [...]
mysql, mysqldump, X shell, 数据备份
一段用于替换字符串中指定的key的代码
–[[User:Fallseir|飞扬轻狂]] 2008年5月6日 (二) 02:32 (PDT)
$str=mapKeys($formatstr,$maps);
$str=“replace this template string !the key maps is herekey1=>{key1},key{{2=>{key{2},key3}=>{key3{}}”;echo mapKeys($str ,array(“key1″=>“value 1″ ,“key{2″=>“value 2″ ,“key3}”=>“value 3″ ));echo “\n”
output>>
replace this template string !the key maps is here
key1=>value 1,key{2=>value 2,key3}=>value 3
abc[the abc value]}}%[%}%%%]%{%[0}%%,%%%,{key],%%,%%[the %value% 2],%%[the %value% 2],%$$%%{,%,
abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%,
$ php -r ‘highlight_file(”test.php”);’
<?php/** test */$str=“replace this template string !the key maps is herekey1=>{key1},key{{2=>{key{2},key3}=>{key3{}}”;echo mapKeys($str ,array(“key1″=>“value 1″ ,“key{2″=>“value 2″ ,“key3}”=>“value 3″ ));echo “\n”;
$str=“abc{key}{}}%{%{}%%%}%{{%{0{}%%,%%%,{key},%%,%%{key,2},%%{key,2},%$$%%{,%,”;echo mapKeys($str,array(“key”=>“[the abc value]“,“key,2″=>“[the %value% 2]“));echo “\n”;
$str=“abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%,”;echo mapKeys($str,array(“key”=>“[the abc value]“ ,“key,2″=>“[the %value% 2]“),“|%|”);echo “\n”;//end test*//*$ php test.phpoutput>>replace this template string !the key maps is herekey1=>value 1,key{2=>value 2,key3}=>value 3abc[the abc value]}}%[%}%%%]%{%[0}%%,%%%,{key],%%,%%[the %value% 2],%%[the %value% 2],%$$%%{,%,abc%%%%%%%%%,%%%,%key%,%%,%%%key,2%,%,%$$%%,%, */ /** * 使用maps中定义的value替换对应其key的由开始标记字符和结束标记字符包含的字符串 * * 当标记对外开始标记后跟着开始标记时或结束标记时表示第一个开始标记为转义符 * 当标记对内开始标记后跟着结束标记时表示第一个开始标记为转义符 * 末尾没有匹配的开始标记将原样输出 */function mapKeys($str,$maps,$fstart=null,$fend=null){ if(!$fstart){ $fstart=“{”; $fend=“}”; } if(!$fend){ $fend=$fstart; } // 如果标记相同则使用mapKeysBase进行替换 if($fstart==$fend){return mapKeysBase($str,$maps,$fstart);} $index=0; $offset=0; while(false!==($index=strpos($str,$fstart,$offset))){ # 找到开始标记,处理开始标记之前的数据 $v=substr($str,$offset,$index-$offset); $offset=$index+strlen($fstart); $p=true; while(($find=substr($str,$offset,strlen($fstart)))==$fstart ||($find=substr($str,$offset,strlen($fend)))==$fend){ $v.=$find; $offset=$offset+strlen($find); $p=false;# 如果这个标记是用来转义的 if(false!==($index=strpos($str,$fstart,$offset))){ $v.=substr($str,$offset,$index-$offset); $offset=$index+strlen($fstart); $p=true;# 查找下一个开始标记 } } $o.=$v; $v=“”; # 标记了开始 并找到了 结束 while($p &&false!==($end=strpos($str,$fend,$offset))){ $v.=substr($str,$offset,$end-$offset); # 如果这个标记是被转义的 if(($find=substr($str,$end-strlen($fend),strlen($fstart))) ==$fstart){ $v=substr($v,0,strlen($v)-strlen($fstart)).$fend; $offset=$end+strlen($fend); continue; } $p=false; } if($v){ if(array_key_exists($v,$maps)){ $v=$maps[$v]; }else{ $v=“[".$v."]“; } $o.=$v; $offset=$end+strlen($fend); } } if($p){ $o.=$fstart; } $v=substr($str,$offset); $o.=$v; return $o;}/** * 使用maps中定义的value替换对应其key的由标记字符包含的字符串 * * 如果标记重复出现 则第一个为转义字符(这也意味着标记字符不能作为key的开始字符) */function mapKeysBase($str,$maps,$find=null){ if(!$find){ $find=“%”; } $p=false; $v=“”; $index=0; $offset=0; while(false!==($index=strpos($str,$find,$offset))){ $v.=substr($str,$offset,$index-$offset); $offset=$index+strlen($find); while(substr($str,$offset,strlen($find))==$find){ $v.=$find; $offset=$offset+strlen($find); if(false!==($index=strpos($str,$find,$offset))){ $v.=substr($str,$offset,$index-$offset); $offset=$index+strlen($find); } } if($p){ if(array_key_exists($v,$maps)){ $v=$maps[$v]; }else{ $v=“[".$v."]“; } $o.=$v; $v=“”; $p=false; }else{ $o.=$v; $v=“”; $p=true; } } if($p){ $v.=$find; } $v.=substr($str,$offset); $o.=$v; return $o;}?>
取自”http://www.fallseir.com/wiki/PHP/MapKeys.html”
fallseir, php
Win下出现apache无法启动的解决方式
使用xampp时,时常会遇到apache启动不了的情况,而xampp的控制面板有没有什么像样的提示 只有一个”Busy…”
但重启Win后,先启动apache就不会遇到问题。
但是事情总是有原因的,决定去查下,也许是xampp给的提示不足,而不是apache的问题,
> cmd
> d:\
> cd tools\xampp\apache\bin\ #我的apache安装位置
> httpd # apache的启动程序
(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 : make_sock: c
ould not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
# 找到原因了 原来是我的80端口被占用了
> netstat -ano # 查看网络状态
Proto Local Address Foreign Address [...]
apache, php, XAMPP
<?phpfunction page_redirect($redirect_to){ if (headers_sent()){ // Use JavaScript to redirect if content has been previously sent (not recommended, but safe) echo ‘<script language=”JavaScript” type=”text/javascript”>window.location=”; echo $redirect_to; echo ”;</script>’; }else{ // Default Header Redirect header(‘Location: ’ . $redirect_to); }}?>
技巧:博客圈的json输出 in feedsky
json: http://network.feedsky.com/test_fn/json?d=0&c=15&p=2&e=gbk&v=obj
feedsky发布了新的博客圈系统,并提供了json输出的支持
上面的代码就是我建的一个博客圈的json输出地址
d代表是否输出描述
c代表输出条数
p代表输出的页面(json版的支持分页显示!)
e代表输出的编码(建议使用utf-8或者gbk!)
v代表输出的变量名
比如这个地址的内容 (http://network.feedsky.com/test_fn/json?d=0&c=1&p=1&e=utf-8&v=obj)
稍微整理了下
obj={
title:’测试博客圈’,
description:’测试博客圈\ntesting…’,
is_page_end:”,
item_count:”,
items:[
{title:'笔记:构建分页导航',
pubDate:'Thu, 07 Jun 2007 16:32:13 +0800',
link:'http://item.feedsky.com/~feedsky/fallseir/~1247382/7460200/1223971/1/item.html'
}],
encoding:’utf-8′
};
obj->
title // 圈子标题
description // 圈子描述
is_page_end [...]