Posts Tagged ‘php’

smarty cache缓存的使用

星期四, 五月 20th, 2010

机器实在太老了。。
在增加到8W条文章
TAG表已经增加到了30多万条了
10 个表 总计 415,762
在我那个老电脑上。。(p4 1.6 256内存)
很快。。内存不足了。。只剩下4MB剩余内存
于是TAOBAO上买了个 512的SDRAM
(全文…)

php+mysql模仿android中短信界面的效果

星期二, 四月 13th, 2010

十分喜欢android的短信
像 QQ一样。。
缺点是。。 发消息也想QQ一样。。。
一条接一条。。 钱也一条接一条的扣。。
哈哈
现在大部分网站的短信都类似于 GMAIL 一样。或者说。跟论坛主题一样。 。 一个贴。。后面回复。。
改变下模式。。做自己喜欢的效果。。
(全文…)

php 全角转半角

星期二, 三月 30th, 2010

找了几个函数
目前用的是第一个,虽然。。。不是很帅。。但是还是比较准的

/**  
 *  将一个字串中含有全角的数字字符、字母、空格或'%+-()'字符转换为相应半角字符  
 *  
 * @access  public  
 * @param   string       $str         待转换字串  
 *  
 * @return  string       $str         处理后字串  
 */  
function make_semiangle($str)   
{   
    $arr = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4',   
                 '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9',   
                 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E',   
                 'F' => 'F', 'G' => 'G', 'H' => 'H', 'I' => 'I', 'J' => 'J',   
                 'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O',   
                 'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T',   
                 'U' => 'U', 'V' => 'V', 'W' => 'W', 'X' => 'X', 'Y' => 'Y',   
                 'Z' => 'Z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd',   
                 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i',   
                 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n',   
                 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's',   
                 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x',   
                 'y' => 'y', 'z' => 'z',   
                 '(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[',   
                 '】' => ']', '〖' => '[', '〗' => ']', '“' => '[', '”' => ']',   
                 '‘' => '[', '’' => ']', '{' => '{', '}' => '}', '《' => '<',   
                 '》' => '>',   
                 '%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-',   
                 ':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.',   
                 ';' => ',', '?' => '?', '!' => '!', '…' => '-', '‖' => '|',   
                 '”' => '"', '’' => '`', '‘' => '`', '|' => '|', '〃' => '"',   
                 ' ' => ' ');   
 
    return strtr($str, $arr);   
}

另外还有一个
看起来很帅的代码
不过貌似有问题
虽然全角是转半角了
但是有部分中文字也出错了貌似。

function &StrToDBC($str,$Encode='GBK'){
 if($Encode!='UTF8')$str=mb_convert_encoding($str,'UTF-8',$Encode);
 $ret='';
 for($i=0;$s1=$str[$i],$i<strlen($str);$i++){
  if(($c=ord($s1))&0x80){
   $s2=$str[++$i];
   $s3=$str[++$i];
   $c=(($c&0xF)<<12)|((ord($s2)&0x3F)<<6)|(ord($s3)&0x3F);
   if($c==12288){
    $ret.=' ';
   }elseif($c>65280&&$c<65375){
    $c-=65248;
    $ret.=chr($c);
   }else{
    $ret.=$s1.$s2.$s3;
   }
  }else{
   $ret.=$str[$i];
  }
 }

PHP时间变成几秒前,几分前,几小时前,几天前SNS模式

星期五, 三月 19th, 2010

最近模仿UCHOME的DOING
我寸在MYSQL的时间都是unix时间。
(全文…)

php jquery ajax中文乱码

星期二, 三月 16th, 2010

PHP发送中文、Ajax接收
只需在php顶部加入一句:

header('Content-type: text/html;charset=GB2312');

xmlHttp会正确解析其中的中文。

Ajax发送中文、PHP接收
这个比较复杂:
Ajax中先用encodeURIComponent对要提交的中文进行编码
PHP中:

$view=iconv( 'UTF-8', 'gb2312//IGNORE' , $_POST['view']);

PHP使用reCAPTCHA作为验证码来保护您的网站

星期一, 三月 15th, 2010

CAPTCHA,其全称是“全自动区分计算机和人类的图灵测试”(completely automated public Turing test to tell computers and humans apart)。
现在通过使用 Google免费的reCAPTCHA服务,您可以轻松地在您自己的网站上利用这项技术。
首先
我们需要申请一个 KEY
类似于GOOGLE MAP的API KEY一样
在reCAPTCHA网站注册一个API key(免费)。并记录下你的private key和 public key。
https://admin.recaptcha.net/accounts/signup/
然后去GOOGLE CODE 下载类库
http://code.google.com/p/recaptcha/downloads/list?q=label:phplib-Latest

调用类

require_once('recaptchalib.php');
$publickey = "..."; // you got this from the signup page
echo recaptcha_get_html($publickey);

验证部分

require_once('recaptchalib.php');
$privatekey = "...";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);
 
if (!$resp->is_valid) {
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
}

官方还提供了一个 EXAMPLE

<html>
  <body>
    <form action="" method="post">
<?php
 
require_once('recaptchalib.php');
$publickey = "...";
$privatekey = "...";
 
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
 
# are we submitting the page?
if ($_POST["submit"]) {
  $resp = recaptcha_check_answer ($privatekey,
                                  $_SERVER["REMOTE_ADDR"],
                                  $_POST["recaptcha_challenge_field"],
                                  $_POST["recaptcha_response_field"]);
 
  if ($resp->is_valid) {
    echo "You got it!";
    # in a real application, you should send an email, create an account, etc
  } else {
    # set the error code so that we can display it. You could also use
    # die ("reCAPTCHA failed"), but using the error message is
    # more user friendly
    $error = $resp->error;
  }
}
echo recaptcha_get_html($publickey, $error);
?>
    <br/>
    <input type="submit" name="submit" value="submit" />
    </form>
  </body>
</html>

DISCUZ的中文分词for php

星期六, 一月 30th, 2010

需要用中文分词来获取TAG
找了DISCUZ的觉得不错,是在线的,不需要本地的词库

<?php    
 
//强制使用字符集    
 
@header('Content-Type: text/html; charset=gbk');    
 
$subjectenc =$_POST['subject'];
 
 
 
$messageenc = preg_replace($_POST['message']);
 
 
$data = @implode('', file("http://keyword.discuz.com/related_kw.html?title=$subjectenc&content=$messageenc&ics=gbk&ocs=gbk")); 
 
if($data) {    
 
$parser = xml_parser_create();//建立一个 XML 解析器    
 
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);    
 
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);    
 
xml_parse_into_struct($parser, $data, $values, $index);//将 XML 数据解析到数组中    
 
xml_parser_free($parser);    
 
$kws = array();    
 
foreach($values as $valuearray) {    
 
  if(in_array($valuearray['tag'],array('kw','ekw'))) {   //kw ekw是什么意思?    
 
    $kws[] = iconv('utf-8','gbk',$valuearray['value']);//编码转换    
 
   }    
 
}}    
 
//最后出来的是数组.    
 
print_r($kws);    
 
?>

PHP $_FILES数组-标记一下

星期一, 一月 11th, 2010

文件上传表单的处理

 
<form action="http://qlj.sh.cn/post.php" enctype="multipart/form-data" method="post">
<input name="MAX_FILE_SIZE" type="hidden" value="1000" />
<input name="upfile" type="file" />
<input type="submit" value="上传文件" />
</form>

(全文…)

人品计算器算法

星期五, 十月 23rd, 2009

人品计算器
一个十分老套的娱乐FLASH
权权在群里又发了

姓名:朱钟权
人品得分:99
评价:你是世人的榜样!

我哥真背啊
1分。
我见过的最低分

姓名:吴少群
人品得分:1
评价:算了,跟你没什么人品好谈的…

我也好不到哪去啊
姓名:钱礼骏
人品得分:68
评价:你的人品勉勉强强..要自己好自为之..
哈这都可以
姓名:午夜yingou
人品得分:99
评价:你是世人的榜样!
为了扭转趋势
来看看到底是怎么计算的
(全文…)

NGINX PHP No input file specified

星期六, 八月 15th, 2009

刚装好

马上加了个 PHPINFO

  1. <?php
  2. phpinfo();
  3. ?>

然后在游览器下运行 结果是

No input file specified.

(全文…)