2011/08/25 at 12:18
AsyncBox(异步盒子)是一款基于 jQuery 的弹窗插件。能够实现网站的整体风格效果,给用户一个新的视觉享受。主要模拟常用的 alert、confirm、prompt、open 和扩展了一些对话框。它通过回调函数触发事件动作并执行,使操作区域更加明了、统一。而且能够在主流浏览器中灵活运用。
介绍及下载地址 http://www.nnhuashi.com/asyncbox/index.html
实例:
$('#select-furns').click(function() {
asyncbox.open({
id: 'select-form',
title: $(this).val(),
url: 'index.php',
width: 700,
height: 400,
tipsbar: {
title: '操作提示',
content: '请先通过下方 <strong>筛选操作</strong>,筛选出你需要的家具。'
},
data: {
module: 'House_Furniture',
load: 'AjaxFurniture',
col_key: '<?php echo $_GET['col_key']; ?>',
lang: '<?php echo getLanguage(); ?>'
}
});
});
注意:如果通过a标签点击弹出,如果a标签的href为javascript:;或javascript:void(0);在ie6下可能会产生阻断,导致页面无法打开
解决的方法是用href=#或者不用a标签
为了防止浏览器跳到顶部,可以加上onclick="return false;" ,或者可以用href=#click这样的形式,这样点击的话如果有id=click的元素浏览器会定位到那里,如果没有,则原地不动
标签:
asyncbox,
jquery
2011/08/25 at 11:58
今天遇到一个项目的修改,由于该项目之前是使用prototype框架,而我拿手的是使用jquery框架,但是又不想全部重写原来的页面效果,所以在页面引入了jquery文件,但是发现原来的js效果消失了,这是因为他们共同使用了$这个对象,造成了重写覆盖,解决方法是重定义jquery的这个对象
首先在页面最开头引入jquery文件,一定要在prototype文件引入之前,然后紧接着重写$
<script type="text/javascript" src="data/jquery.min.js"></script>
<script type="text/javascript">
var jQuery=$;
</script>
然后在后面运用jquery时把原来使用$的地方全部换成jQuery就可以了
标签:
jquery,
prototype
2011/08/24 at 23:53
在linux虚拟主机下一般可以利用php的mail函数直接发邮件
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
但是在windows虚拟主机下则不能直接使用mail函数,可以通过socket了,采用邮箱的smtp服务在线发送邮件(现在的163免费邮箱一注册就可以免费使用这个服务,并且默认开通的),比较成熟的在线发送邮件类有php_mailer,功能很强大,不过下面介绍的是一个比较简单的socket邮件发送类,应付一般的需求足够了。
使用方法是:
require_once (dirname(__FILE__).'/email.class.php');//该类的代码附在文章后面
//##########################################
$smtpserver = "smtp.163.com";//SMTP服务器
$smtpserverport =25;//SMTP服务器端口
$smtpusermail = "XXX@163.com";//SMTP服务器的用户邮箱
$smtpemailto = "XXXXX@qq.com";//发送给谁
$smtpuser = "s_XXX";//SMTP服务器的用户帐号
$smtppass = "aaa123456";//SMTP服务器的用户密码
$mailsubject = "收到用户的产品询价";//邮件主题
$mailbody = "用户提交了产品询价,请登录网站后台查看!";//邮件内容
$mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件
//##########################################
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
$smtp->debug = false;//是否显示发送的调试信息
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
附简单的邮件发送类代码
<?
class smtp
{
/* Public Variables */
var $smtp_port;
var $time_out;
var $host_name;
var $log_file;
var $relay_host;
var $debug;
var $auth;
var $user;
var $pass;
/* Private Variables */
var $sock;
/* Constractor */
function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass)
{
$this->debug = FALSE;
$this->smtp_port = $smtp_port;
$this->relay_host = $relay_host;
$this->time_out = 30; //is used in fsockopen()
#
$this->auth = $auth;//auth
$this->user = $user;
$this->pass = $pass;
#
$this->host_name = "localhost"; //is used in HELO command
$this->log_file ="";
$this->sock = FALSE;
}
/* Main Function */
function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "")
{
$mail_from = $this->get_address($this->strip_comment($from));
$body = ereg_replace("(^|(\r\n))(\\.)", "\\1.\\3", $body);
$header .= "MIME-Version:1.0\r\n";
if($mailtype=="HTML"){
$header .= "Content-Type:text/html\r\n";
}
$header .= "To: ".$to."\r\n";
if ($cc != "") {
$header .= "Cc: ".$cc."\r\n";
}
$header .= "From: $from<".$from.">\r\n";
$header .= "Subject: ".$subject."\r\n";
$header .= $additional_headers;
$header .= "Date: ".date("r")."\r\n";
$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";
$TO = explode(",", $this->strip_comment($to));
if ($cc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));
}
if ($bcc != "") {
$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));
}
$sent = TRUE;
foreach ($TO as $rcpt_to) {
$rcpt_to = $this->get_address($rcpt_to);
if (!$this->smtp_sockopen($rcpt_to)) {
$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");
$sent = FALSE;
continue;
}
if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");
} else {
$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");
$sent = FALSE;
}
fclose($this->sock);
$this->log_write("Disconnected from remote host\n");
}
//echo "<br>";
//echo $header;
return $sent;
}
/* Private Functions */
function smtp_send($helo, $from, $to, $header, $body = "")
{
if (!$this->smtp_putcmd("HELO", $helo)) {
return $this->smtp_error("sending HELO command");
}
#auth
if($this->auth){
if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {
return $this->smtp_error("sending HELO command");
}
if (!$this->smtp_putcmd("", base64_encode($this->pass))) {
return $this->smtp_error("sending HELO command");
}
}
#
if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {
return $this->smtp_error("sending MAIL FROM command");
}
if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {
return $this->smtp_error("sending RCPT TO command");
}
if (!$this->smtp_putcmd("DATA")) {
return $this->smtp_error("sending DATA command");
}
if (!$this->smtp_message($header, $body)) {
return $this->smtp_error("sending message");
}
if (!$this->smtp_eom()) {
return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]");
}
if (!$this->smtp_putcmd("QUIT")) {
return $this->smtp_error("sending QUIT command");
}
return TRUE;
}
function smtp_sockopen($address)
{
if ($this->relay_host == "") {
return $this->smtp_sockopen_mx($address);
} else {
return $this->smtp_sockopen_relay();
}
}
function smtp_sockopen_relay()
{
$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
return FALSE;
}
$this->log_write("Connected to relay host ".$this->relay_host."\n");
return TRUE;;
}
function smtp_sockopen_mx($address)
{
$domain = ereg_replace("^.+@([^@]+)$", "\\1", $address);
if (!@getmxrr($domain, $MXHOSTS)) {
$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");
return FALSE;
}
foreach ($MXHOSTS as $host) {
$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");
$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);
if (!($this->sock && $this->smtp_ok())) {
$this->log_write("Warning: Cannot connect to mx host ".$host."\n");
$this->log_write("Error: ".$errstr." (".$errno.")\n");
continue;
}
$this->log_write("Connected to mx host ".$host."\n");
return TRUE;
}
$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");
return FALSE;
}
function smtp_message($header, $body)
{
fputs($this->sock, $header."\r\n".$body);
$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));
return TRUE;
}
function smtp_eom()
{
fputs($this->sock, "\r\n.\r\n");
$this->smtp_debug(". [EOM]\n");
return $this->smtp_ok();
}
function smtp_ok()
{
$response = str_replace("\r\n", "", fgets($this->sock, 512));
$this->smtp_debug($response."\n");
if (!ereg("^[23]", $response)) {
fputs($this->sock, "QUIT\r\n");
fgets($this->sock, 512);
$this->log_write("Error: Remote host returned \"".$response."\"\n");
return FALSE;
}
return TRUE;
}
function smtp_putcmd($cmd, $arg = "")
{
if ($arg != "") {
if($cmd=="") $cmd = $arg;
else $cmd = $cmd." ".$arg;
}
fputs($this->sock, $cmd."\r\n");
$this->smtp_debug("> ".$cmd."\n");
return $this->smtp_ok();
}
function smtp_error($string)
{
$this->log_write("Error: Error occurred while ".$string.".\n");
return FALSE;
}
function log_write($message)
{
$this->smtp_debug($message);
if ($this->log_file == "") {
return TRUE;
}
$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;
if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {
$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");
return FALSE;
}
flock($fp, LOCK_EX);
fputs($fp, $message);
fclose($fp);
return TRUE;
}
function strip_comment($address)
{
$comment = "\\([^()]*\\)";
while (ereg($comment, $address)) {
$address = ereg_replace($comment, "", $address);
}
return $address;
}
function get_address($address)
{
$address = ereg_replace("([ \t\r\n])+", "", $address);
$address = ereg_replace("^.*<(.+)>.*$", "\\1", $address);
return $address;
}
function smtp_debug($message)
{
if ($this->debug) {
echo $message."<br>";
}
}
function get_attach_type($image_tag) { //
$filedata = array();
$img_file_con=fopen($image_tag,"r");
unset($image_data);
while ($tem_buffer=AddSlashes(fread($img_file_con,filesize($image_tag))))
$image_data.=$tem_buffer;
fclose($img_file_con);
$filedata['context'] = $image_data;
$filedata['filename']= basename($image_tag);
$extension=substr($image_tag,strrpos($image_tag,"."),strlen($image_tag)-strrpos($image_tag,"."));
switch($extension){
case ".gif":
$filedata['type'] = "image/gif";
break;
case ".gz":
$filedata['type'] = "application/x-gzip";
break;
case ".htm":
$filedata['type'] = "text/html";
break;
case ".html":
$filedata['type'] = "text/html";
break;
case ".jpg":
$filedata['type'] = "image/jpeg";
break;
case ".tar":
$filedata['type'] = "application/x-tar";
break;
case ".txt":
$filedata['type'] = "text/plain";
break;
case ".zip":
$filedata['type'] = "application/zip";
break;
default:
$filedata['type'] = "application/octet-stream";
break;
}
return $filedata;
}
}
?>
标签:
email,
php
2011/08/24 at 22:09
网站上线19天,今天百度终于收录了首页,总算度过了这个漫长的考核期,虽然网上一般说法是百度对新站会有一个月左右的考核期,现在这个时候收录应该算正常吧,接下来会不会像某些新站一样很长一段时间只收录首页就要继续观察了。
网站上线第二天,谷歌百度的蜘蛛就造访了,谷歌很快就收录并放出了抓到的页面,百度就先抓取不显示,刚开始两条蜘蛛都非常勤快,百度蜘蛛最多一天爬300多次,谷歌蜘蛛3000多次,现在每天一般是前者100次,后者2000次这样的频率。
谷歌收录页面数量一直都是稳定地增长,到昨天达到将近6000个页面,并且谷歌给这个博客的权重还算比较高的,关键词都能获得比较好的排名,每天都会有不少ip是通过谷歌搜索技术问题过来的,并且谷歌对新文章的反应速度极快,基本上发一篇新博文在两三分钟内会被收录并且放出来。
百度虽然也会比较快抓取新文章,但是就是不放出,在8月10号也就是10天前放出了通过ip抓取的首页,然后就一直没更新快照,前天我把ip都301到域名下来,那个应该不会再更新了。
这期间没有去做什么外链,只是在博客里面对百度做了一点小小的优化,不知道对今天的收录有没有一点影响。
说实话我还是比较看重网站在百度的表现,谷歌退出大陆之后,在市场份额方面已经很难跟百度抗衡了,百度现在拥有中国大陆绝大部分的搜索流量,对网站的收录情况直接影响到网站的访问量。
标签:
seo,
收录,
百度,
谷歌
2011/08/23 at 14:13
如果在根目录和子目录下都存在htaccess文件,默认根目录下htaccess的规则是不会被继承的,如果这些配置需要影响到子目录,需要手动写上"RewriteOptions inherit"才能继承父配置,参考上一篇 htaccess的用法 。
所以如果子目录也要用到根目录的配置规则,最好是重新定义,因为如果单纯的继承的话,根目录htaccess里面的某些规则的路径可能已经不适用子目录。
标签:
htaccess
2011/08/23 at 14:06
以下指命令的作用域都是.htaccess
RewriteEngine On|Off
RewriteEngine 可用On 或者 Off 打开或关闭rewrite功能。
rewrite configurations 不会继承,所以你得给每个你想用 rewrite功能的virtual host加上这个指令。
RewriteBase URL-path
RewriteBase指令显式地设置了目录级重写的基准URL。在下文中,你可以看见RewriteRule可以用于目录级的配置文件中 (.htaccess)并在局部范围内起作用,即规则实际处理的只是剥离了本地路径前缀的一部分。处理结束后,这个路径会被自动地附着回去。默认值是"RewriteBase physical-directory-path"。
在对一个新的URL进行替换时,此模块必须把这个URL重新注入到服务器处理中。为此,它必须知道其对应的URL前缀或者说URL基准。通常,此前缀就是对应的文件路径。但是,大多数网站URL不是直接对应于其物理文件路径的,因而一般不能做这样的假定! 所以在这种情况下,就必须用RewriteBase指令来指定正确的URL前缀。
如果你的网站服务器URL不是与物理文件路径直接对应的,而又需要使用RewriteBase指令,则必须在每个对应的.htaccess文件中指定RewriteRule 。
RewriteCond TestString CondPattern
RewriteCond指令定义了一个规则的条件,即在一个RewriteRule指令之前有一个或多个RewriteCond指令。条件之后的重写规则仅在当前URI与pattern匹配并且符合这些条件的时候才会起作用。
Notice:All of these tests can also be prefixed by an exclamation mark ('!') to negate their meaning. 在正则表达式中,如果取反的话要用^,在这里需要用!号取反
RewriteOptions Options
Sets some special options for the rewrite engine.
设定一些特殊的选项给rewrite.
The Option string can be currently only one:inherit
inherit
此值强制当前配置可以继承其父配置。 在虚拟主机级配置中,它意味着主服务器的映射表、条件和规则可以被继承。 在目录级配置中,它意味着其父目录的.htaccess中的条件和规则可以被继承。
MaxRedirects=number
为了避免目录级RewriteRule的无休止的内部重定向, 在此类重定向和500内部服务器错误次数达到一个最大值的时候, mod_rewrite会停止对此请求的处理。 如果你确实需要对每个请求允许大于10次的内部重定向,可以增大这个值。
This forces the current configuration to inherit the configuration of the parent.
强制当前的配置继承它parent的配置。
在per-virtual-server环境下,意味着maps, conditions , rules会被继承!
在per-directory 环境下 意味着它父目录的.htaccess配置中的conditions , rules 会被继承!
RewriteRule Pattern Substitution [flags]
Text:
. 任何单字符
[chars] Character class: One of chars
[^chars] Character class: None of chars
text1|text2 两者选一个: text1 or text2
Quantifiers:量词
? 0 or 1 of the 前面的 text
* 0 or N of the 前面的 text (N > 0)
+ 1 or N of the 前面的 text (N > 1)
Grouping:
(text) Grouping of text
可用$N来得到()中的内容:
( (a|b) | (c|d))
$1 $2 $3
Anchors:
^ Start of line anchor
$ End of line anchor
Escaping:
\char escape that particular char
(for instance to specify the chars ".[]()" etc.)
注意:没有并且&
=========================================================================================
flags
1.
'redirect|R [=code]' (强制重定向 redirect)
以http://thishost[:thisport]/(使新的URL成为一个URI) 为前缀的Substitution可以强制性执行一个外部重定向。 如果code没有指定,则产生一个HTTP响应代码302(临时性移动)。 如果需要使用在300-400范围内的其他响应代码,只需在此指定这个数值即可, 另外,还可以使用下列符号名称之一: temp (默认的), permanent, seeother. 用它可以把规范化的URL反馈给客户端,如, 重写``/~''为 ``/u/'',或对/u/user加上斜杠,等等。 注意: 在使用这个标记时,必须确保该替换字段是一个有效的URL! 否则,它会指向一个无效的位置! 并且要记住,此标记本身只是对URL加上 http://thishost[:thisport]/的前缀,重写操作仍然会继续。 通常,你会希望停止重写操作而立即重定向,则还需要使用'L'标记.
2.
'forbidden|F' (强制URL为被禁止的 forbidden)
强制当前URL为被禁止的,即,立即反馈一个HTTP响应代码403(被禁止的)。 使用这个标记,可以链接若干RewriteConds以有条件地阻塞某些URL。
3.
'gone|G' (强制URL为已废弃的 gone)
强制当前URL为已废弃的,即,立即反馈一个HTTP响应代码410(已废弃的)。 使用这个标记,可以标明页面已经被废弃而不存在了.
4.
'proxy|P' (强制为代理 proxy)
此标记使替换成分被内部地强制为代理请求,并立即(即, 重写规则处理立即中断)把处理移交给代理模块。 你必须确保此替换串是一个有效的(比如常见的以 http://hostname开头的)能够为Apache代理模块所处理的URI。 使用这个标记,可以把某些远程成分映射到本地服务器名称空间, 从而增强了ProxyPass指令的功能。 注意: 要使用这个功能,代理模块必须编译在Apache服务器中。 如果你不能确定,可以检查``httpd -l''的输出中是否有mod_proxy.c。 如果有,则mod_rewrite可以使用这个功能; 如果没有,则必须启用mod_proxy并重新编译``httpd''程序。
5.
'last|L' (最后一个规则 last)
立即停止重写操作,并不再应用其他重写规则。 它对应于Perl中的last命令或C语言中的break命令。 这个标记可以阻止当前已被重写的URL为其后继的规则所重写。 举例,使用它可以重写根路径的URL('/')为实际存在的URL, 比如, '/e/www/'.
6.
'next|N' (重新执行 next round)
重新执行重写操作(从第一个规则重新开始). 这时再次进行处理的URL已经不是原始的URL了,而是经最后一个重写规则处理的URL。 它对应于Perl中的next命令或C语言中的continue命令。 此标记可以重新开始重写操作,即, 立即回到循环的头部。但是要小心,不要制造死循环!
7.
'chain|C' (与下一个规则相链接 chained)
此标记使当前规则与下一个(其本身又可以与其后继规则相链接的, 并可以如此反复的)规则相链接。 它产生这样一个效果: 如果一个规则被匹配,通常会继续处理其后继规则, 即,这个标记不起作用;如果规则不能被匹配, 则其后继的链接的规则会被忽略。比如,在执行一个外部重定向时, 对一个目录级规则集,你可能需要删除``.www'' (此处不应该出现``.www''的)。
8.
'type|T=MIME-type' (强制MIME类型 type)
强制目标文件的MIME类型为MIME-type。 比如,它可以用于模拟mod_alias中的ScriptAlias指令, 以内部地强制被映射目录中的所有文件的MIME类型为``application/x-httpd-cgi''.
9.
'nosubreq|NS' (仅用于不对内部子请求进行处理 no internal sub-request)
在当前请求是一个内部子请求时,此标记强制重写引擎跳过该重写规则。 比如,在mod_include试图搜索可能的目录默认文件(index.xxx)时, Apache会内部地产生子请求。对子请求,它不一定有用的,而且如果整个规则集都起作用, 它甚至可能会引发错误。所以,可以用这个标记来排除某些规则。 根据你的需要遵循以下原则: 如果你使用了有CGI脚本的URL前缀,以强制它们由CGI脚本处理, 而对子请求处理的出错率(或者开销)很高,在这种情况下,可以使用这个标记。
10.
'nocase|NC' (忽略大小写 no case)
它使Pattern忽略大小写,即, 在Pattern与当前URL匹配时,'A-Z' 和'a-z'没有区别。
11.
'qsappend|QSA' (追加请求串 query string append)
此标记强制重写引擎在已有的替换串中追加一个请求串,而不是简单的替换。 如果需要通过重写规则在请求串中增加信息,就可以使用这个标记。
12.
'noescape|NE' (在输出中不对URI作转义 no URI escaping)
此标记阻止mod_rewrite对重写结果应用常规的URI转义规则。 一般情况下,特殊字符(如'%', '$', ';'等)会被转义为等值的十六进制编码。 此标记可以阻止这样的转义,以允许百分号等符号出现在输出中,如: RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
可以使'/foo/zed'转向到一个安全的请求'/bar?arg=P1=zed'.
13.
'passthrough|PT' (移交给下一个处理器 pass through)
此标记强制重写引擎将内部结构request_rec中的uri字段设置为 filename字段的值,它只是一个小修改,使之能对来自其他URI到文件名翻译器的 Alias,ScriptAlias, Redirect 等指令的输出进行后续处理。举一个能说明其含义的例子: 如果要通过mod_rewrite的重写引擎重写/abc为/def, 然后通过mod_alias使/def转变为/ghi,可以这样: RewriteRule ^/abc(.*) /def$1 [PT]
Alias /def /ghi
如果省略了PT标记,虽然mod_rewrite运作正常, 即, 作为一个使用API的URI到文件名翻译器, 它可以重写uri=/abc/...为filename=/def/..., 但是,后续的mod_alias在试图作URI到文件名的翻译时,则会失效。
注意: 如果需要混合使用不同的包含URI到文件名翻译器的模块时, 就必须使用这个标记。混合使用mod_alias和mod_rewrite就是个典型的例子。
For Apache hackers
如果当前Apache API除了URI到文件名hook之外,还有一个文件名到文件名的hook, 就不需要这个标记了! 但是,如果没有这样一个hook,则此标记是唯一的解决方案。 Apache Group讨论过这个问题,并在Apache 2.0 版本中会增加这样一个hook。
14.
'skip|S=num' (跳过后继的规则 skip)
此标记强制重写引擎跳过当前匹配规则后继的num个规则。 它可以实现一个伪if-then-else的构造: 最后一个规则是then从句,而被跳过的skip=N个规则是else从句. (它和'chain|C'标记是不同的!)
15.
'env|E=VAR:VAL' (设置环境变量 environment variable)
此标记使环境变量VAR的值为VAL, VAL可以包含可扩展的反向引用的正则表达式$N和%N。 此标记可以多次使用以设置多个变量。 这些变量可以在其后许多情况下被间接引用,但通常是在XSSI (via or CGI (如 $ENV{'VAR'})中, 也可以在后继的RewriteCond指令的pattern中通过%{ENV:VAR}作引用。 使用它可以从URL中剥离并记住一些信息。
16.
'cookie|CO=NAME:VAL:domain[:lifetime[:path]]' (设置cookie)
它在客户端浏览器上设置一个cookie。 cookie的名称是NAME,其值是VAL。 domain字段是该cookie的域,比如'.apache.org', 可选的lifetime是cookie生命期的分钟数, 可选的path是cookie的路径。
标签:
flag,
htaccess
2011/08/20 at 14:54
定界符:
另一种给字符串定界的方法使用定界符语法("<<<")。应该在 <<< 之后提供一个标识符,然后是字符串,然后是同样的标识符结束字符串。
结束标识符必须从行的第一列开始。同样,标识符也必须遵循 PHP 中其它任何标签的命名规则:只能包含字母数字下划线,而且必须以下划线或非数字字符开始。
php 中(<<<eot)的用法
有时候我们需要在php输出比较复杂的html文本,如果使用双引号的话,文本里面有双引号的
例:
<?php
while($rs=$db->fetch_array($news)){
echo <<<EOT
<li>
<a href="?{$rs[id]}">{$rs[title]}</a><img src="images/new.gif" alt=""><span>[{$rs[date]}]</span></li>
EOT; //注意,此处的EOT;必须在当前行的最前,其前面不允许有任何字符
?>
从上面的例子可以看出<<<eot为开始标识,结束为eot; 中间引用变量则就为{变量} 这种方法通常用在生成静态度页面时,可以把此代码写在静态文件中,然后然后用来调用即可
定界符
给字符串定界的方法使用定界符语法("<<<")。应该在 <<< 之后提供一个标识符,然后是字符串,然后是同样的标识符结束字符串。
结束标识符必须从行的第一列开始。同样,标识符也必须遵循 PHP 中其它任何标签的命名规则:只能包含字母数字下划线,而且必须以下划线或非数字字符开始。
举个例子:
<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
?>
但要注意的是:
结束标识符所在的行不能包含任何其它字符,可能除了一个分号(;)之外。这尤其意味着该标识符不能被缩进,而且在分号之前和之后都不能有任何空格或制表符。同样重要的是要意识到在结束标识符之前的第一个字符必须是你的操作系统中定义的换行符。例如在 Macintosh 系统中是 \r。 如果破坏了这条规则使得结束标识符不"干净",则它不会被视为结束标识符,PHP 将继续寻找下去。如果在这种情况下找不到合适的结束标识符,将会导致一个在脚本最后一行出现的语法错误。
如下:
print <<<eot
eot;
中间可以放置变量的,如果是数组变量也是可以的。
假如数组
$arrTest=array("abc","123");
在eot之间可以用以下方式置入变量
"{$arrTest[0]}"
标签:
EOT,
定界符
2011/08/19 at 23:37
通过网站的服务器日志分析,百度经常会先访问博客文章的动态页,再被301重定向到固定链接,可能由于wordpress是国外的产物,没有专门针对百度做seo,甚至连robots文件都没有,今天主要做了以下优化工作,过几天看效果如何:
一,安装wp的百度地图插件:Baidu Sitemap Generator,生成网站地图
插件使用方法:
1.在 http://www.tianchuangseo.com/wp-content/uploads/2010/09/baidu-sitemap-generator.zip 下载插件,安装并激活。
2.点击设置里面的 Baidu-Sitemap 选项,即可看到设置界面,第一次使用你需要先激活配置。
3.然后点击"更新 XML 文件"按钮即可生成上述的 XML 文件和 Html 静态页面。
4.在你网站的合适位置加入这两个链接即可。
二,添加robots.txt文件,文件内容为:
User-agent: *
Disallow: /wp-
Allow: /wp-content/uploads/
Disallow: /?
Disallow: /feed
Disallow: /*/*/feed
Disallow: /trackback
Disallow: /*/*/trackback
Disallow: /index.php?
Disallow: /index.php/
Disallow: /*.php$
Disallow: /*.css$
Disallow: /date/
Sitemap: http://www.zui88.com/blog/sitemap_baidu.xml
Sitemap: http://www.zui88.com/blog/sitemap.html
三,在百度博客提交页面提交了博客feed地址 http://ping.baidu.com/ping.html
四,设置wordrpess的自动ping服务。登陆博客后台,选择"设置"->"撰写"功能模块,在更新服务ping service那一栏填写各个Ping中心地址保存即可。
百度博客的ping中心地址是:http://ping.baidu.com/ping/RPC2
我这边添加的ping地址是:
http://rpc.pingomatic.com/
http://ping.baidu.com/ping/RPC2
http://blogsearch.google.com/ping/RPC2
http://api.my.yahoo.com/RPC2
http://api.my.yahoo.com/rss/ping
http://ping.feedburner.com
http://www.zhuaxia.com/rpc/server.php
http://www.xianguo.com/xmlrpc/ping.php
http://www.feedsky.com/api/RPC2
http://blog.iask.com/RPC2
http://ping.blog.qikoo.com/rpc2.php
http://rpc.technorati.com/rpc/ping
http://www.blogsdominicanos.com/ping/
标签:
ping,
seo,
优化
2011/08/19 at 18:04
smarty在模板上可以直接使用php自带的函数,甚至可以使用自定义的函数,使用的方法是:
模板中调用变量时,当只有一个参数是,就直接{$str1|函数名},当有函数有两个参数时,{第一个参数|函数名:第二个参数},当有三个参数时,{第一个参数|函数名:第二个参数:第三个参数},,当有4,5,,,参数时,以此类推。
smarty使用date函数的用法是{{'Y-m-d'|date:
$var}}
标签:
smarty
2011/08/19 at 16:56
date — 格式化一个本地时间/日期(把时间戳变成文本格式)
string date ( string $format [, int $timestamp ] )
timestamp 是可选的,默认值为 time()。
$today = date("H:i:s"); // 17:16:17
getdate — 取得日期/时间信息(把时间戳的信息存到数组)
array getdate ([ int $timestamp ] )
<?php
$today = getdate();
print_r($today);
?>
返回
Array
(
[seconds] => 40
[minutes] => 58
[hours] => 21
[mday] => 17
[wday] => 2
[mon] => 6
[year] => 2003
[yday] => 167
[weekday] => Tuesday
[month] => June
[0] => 1055901520
)
strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳 (把文本格式变成时间戳)
int strtotime ( string $time [, int $now ] )
函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数则用系统当前时间。
<?php
echo strtotime("2011-9-9"), "\n";
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>
strtotime的第一个参数可以是我们常见的英文时间格式,比如"2008-8-20"或"10 September 2000"等等。也可以是以参数now为基准的时间描述,比如"+1 day"等等。
下面是后一种方式的可使用参数清单,其中"当前时间"是指strtotime第二个参数now的值,默认为当前时间。
1. 月,日英文名及其常用缩写清单:
january,february,march,april,may,june,july,august,september,sept,october,november,december,
sunday,monday,tuesday,tues,wednesday,wednes,thursday,thur,thurs,friday,saturday
2. 时间参数和祥细描述:
am: the time is before noon 上午
pm: the time is noon or later 下午
year: one year; for example, "next year" 年,比如"next year"代表明年
month: one month; for example, "last month" 月,比如"last month"代表上一月
fortnight: two weeks; for example, "a fortnight ago" 两周,比如"a fortnight ago"代表两周前
week: one week 周
day: a day 天
hour: an hour 小时
minute: a minute 分钟
min: same as minute 同"minute"
second: a second 秒
sec: same as second 同"second"
3.相关和顺序说明:
+n/-n:以当前时间算,加个减指定的时间,比如"+1 hour"是指当前时间加一小时
ago:time relative to now; such as "24 hours ago" 以当前时间往前算,比如"24 hours ago"代表"24小时前"
tomorrow: 24 hours later than the current date and time 以当前时间(包括日期和时间)为标准,明天同一时间
yesterday: 24 hours earlier than the current date and time 以当前时间(包括日期和时间)为标准,昨天同一时间
today: the current date and time 当前时间(包括日期和时间)
now: the current date and time 当前时间(包括日期和时间)
last: modifier meaning "the preceding"; for example, "last tuesday" 代表"上一个",比如"last tuesday"代表"上周二同一时间"
this: the given time during the current day or the next occurrence of the given time; for example, "this 7am" gives the timestamp for 07:00 on the current day, while "this week" gives the timestamp for one week from the current time 当天的指定时间或下面一个时间段的时间戳,比如"this 7am"给出当天7:00的时间戳,而"this week"给出的是从当前时间开始的一整周的时间戳,也就是当前时间(经本人测试:strtotime('this week')=strtotime('now'));
next: modifier meaning the current time value of the subject plus one; for example, "next hour" 当前时间加上指定的时间,比如"next hour"是指当前时间加上一小时,即加3600
first: ordinal modifier, esp. for months; for example, "May first" (actually, it's just the same as next)
third: see first (note that there is no "second" for ordinality, since that would conflict with the second time value)
fourth: see first
fifth: see first
sixth: see first
seventh: see first
eighth: see first
ninth: see first
tenth: see first
eleventh: see first
twelfth: see first
4. 时区描述:
gmt: Greenwich Mean Time
ut: Coordinated Universal Time
utc: same as ut
wet: Western European Time
bst: British Summer Time
wat: West Africa Time
at: Azores Time
ast: Atlantic Standard Time
adt: Atlantic Daylight Time
est: Eastern Standard Time
edt: Eastern Daylight Time
cst: Central Standard Time
cdt: Central Daylight Time
mst: Mountain Standard Time
mdt: Mountain Daylight Time
pst: Pacific Standard Time
pdt: Pacific Daylight Time
yst: Yukon Standard Time
ydt: Yukon Daylight Time
hst: Hawaii Standard Time
hdt: Hawaii Daylight Time
cat: Central Alaska Time
akst: Alaska Standard Time
akdt: Alaska Daylight Time
ahst: Alaska-Hawaii Standard Time
nt: Nome Time
idlw: International Date Line West
cet: Central European Time
met: Middle European Time
mewt: Middle European Winter Time
mest: Middle European Summer Time
mesz: Middle European Summer Time
swt: Swedish Winter Time
sst: Swedish Summer Time
fwt: French Winter Time
fst: French Summer Time
eet: Eastern Europe Time, USSR Zone 1
bt: Baghdad Time, USSR Zone 2
zp4: USSR Zone 3
zp5: USSR Zone 4
zp6: USSR Zone 5
wast: West Australian Standard Time
wadt: West Australian Daylight Time
cct: China Coast Time, USSR Zone 7
jst: Japan Standard Time, USSR Zone 8
east: Eastern Australian Standard Time
eadt: Eastern Australian Daylight Time
gst: Guam Standard Time, USSR Zone 9
nzt: New Zealand Time
nzst: New Zealand Standard Time
nzdt: New Zealand Daylight Time
idle: International Date Line East
strftime — 根据区域设置格式化本地时间/日期 (把时间戳变成文本格式)
string strftime ( string $format [, int $timestamp ] )
strftime()工作的方式和date()没有什么不同,除了特殊格式化字符的前面必须添加一个百分号%。
strftime()有两个好处。第一个好处是如果你使用setlocale()函数,你可以通过strftime得到相应语言的月份的名称。另外的一个好处是你可以将特别的日期和时间的格式化字符包含在你的字符串中。这同时也意味着无论你是否要学习date()函数的所有特殊格式化字符,你都必须学习一整套完全不同的格式化字符。
一般phper用date会比较顺手吧。
strptime — 解析由 strftime() 生成的日期/时间 (把文本格式的日期信息存到数组)
array strptime ( string $date , string $format )
类似于date函数的getdate
<?php
$format = '%d/%m/%Y %H:%M:%S';
$strf = strftime($format);
echo "$strf\n";
print_r(strptime($strf, $format));
?>
输出
03/10/2004 15:54:19
Array
(
[tm_sec] => 19
[tm_min] => 54
[tm_hour] => 15
[tm_mday] => 3
[tm_mon] => 9
[tm_year] => 104
[tm_wday] => 0
[tm_yday] => 276
[unparsed] =>
)
time — 返回当前的 Unix 时间戳
int time ( void )
mktime — 取得一个日期的 Unix 时间戳
int mktime ([ int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst ]]]]]]] )
参数可以从右向左省略,任何省略的参数会被设置成本地日期和时间的当前值,参数全部为空则与time()相同
microtime — 返回当前 Unix 时间戳和微秒数
microtime() 当前 Unix 时间戳以及微秒数。本函数仅在支持 gettimeofday() 系统调用的操作系统下可用。
如果调用时不带可选参数,本函数以 "msec sec" 的格式返回一个字符串,其中 sec 是自 Unix 纪元(0:00:00 January 1, 1970 GMT)起到现在的秒数,msec 是微秒部分。字符串的两部分都是以秒为单位返回的。
如果给出了 get_as_float 参数并且其值等价于 TRUE,microtime() 将返回一个浮点数。默认为false
<?php
echo microtime(true);//1313743963.77
echo microtime(false);//0.10190200 1313744036
?>
标签:
php,
日期函数