关于PHP的addslashes(), stripslashes(), magic_quotes_gpc(), mysql_real_escape_string()

addslashes()

为 单引号 ('),双引号 ("),反斜杠 (\),NULL 加转义反斜杠。注意,这里不包括 分号(;),如果使用这个来转义,保险起见,在使用addslashes之后,用字符串替换将分号替换成转义的形式(\;)比较好。

stripslashes()

将addslashes处理过的字符串恢复。

mysql_real_escape_string()

可以将MYSQL查询中可能出现的特殊字符都转义掉,所以,在mysql_query()之前,用它处理一下是很不错的,但只在PHP4.3.0之后被支持,并且要注意,

magic_quotes_gpc()

如果magic_quotes_gpc 为 on,所有的 GET、POST 和 COOKIE 数据会被自动运行 addslashes()。

考虑到上述问题之后的转义函数:

function escape_str($str){ 
  if(PHP_VERSION >= "4.3.0"){ 
    if(get_magic_quotes_gpc()) $str=stripslashes($str); 
    $str=mysql_real_escape_string($str); 
  }else{ 
    if(!get_magic_quotes_gpc()) $str=addslashes($str); 
      $str=str_replace($str,";",'\;'); 
  } 
  return $str; 
}

字符串转义图解

php英文字母累加函数

Lane的PHP练习作品。十分感谢我师傅
累加形式如下:
A,B,C,D...X,Y,Z,AA,AB...AZ,BA,BB...
也就是说如果传入参数是ZZ,那么返回的就是AAA。

//code by liuyuanjun.com
function LetterAdd($s){
    $Str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $len = strlen($s);
    $i = 1;
    do{
        $a2 = substr($s,$len-$i,1);
        $pos = strpos($Str,$a2)+1;
        $b2 = $pos>25 ? "A" : $Str[$pos];
        $a1 = $len==$i ? ($b2=="A"?"A":"") : substr($s,0,$len-$i);
        $a3 = $i==1 ? "" : substr($s,$len-$i+1);
        $s = $a1.$b2.$a3;
        $i++;
    }while($b2=="A" && $len>$i-1);
    return $s;
}

for($i=A;$i!="AAA";$i=LetterAdd($i)){
    echo $i."
";
}

文章没有版权,转载请留链接。

PHP柱状图函数

原始HTML大概是从BLUEIDEA得来的吧,记不清了。
PHP我写的,也写了好久了。
现在不用了,在BLOG上留个记录。
CSS部分:

<style type="text/css">
<!--
    ul.q-graph {border:2px solid #0063be;    background:#ffc url(images/graphbg.png) repeat-x scroll 0 0 !important;background:#ffc repeat-x scroll 0 0;    position:relative;list-style:none;margin:1.1em 0 3.5em 0;    padding:0;}
    .q-graph li {    position:absolute;text-align:center;bottom:0;padding:0;margin:0;}
    li.qtr {border-right:1px dotted #41a3e2; word-wrap:break-word; z-index:2;}
    .q-graph ul {list-style:none;}
    li.bar {width:34px; font-size:9px;    color:#fff;    background:#ddd url('images/graphbar.gif') no-repeat -34px 0;}
    li.ticks {left:0;width:100%;z-index:1;}
    div.ticks {position:relative;margin:0;border-top:1px dotted #41a3e2;}
    div.ticks:first-child {border-top:none;}    /*only4 Firefx IE 7+*/
    div.ticks p {position:absolute;left:101%;top:-2px;margin:0;color:#f00;    font-weight:bold;}
-->
</style>

PHP部分:

阅读剩余部分...

饼形图表

在经典上找了个VML图表,可惜只有ASP的输出程序,废半天劲改成PHP的,又加入url传递参数,好乱,眼睛都花了。
VML我不懂,不知哪里有问题,在IE8下,鼠标放上去显示出的百分比不正常。如果有知道的人麻烦告知一下谢谢。

查看效果

==========

用家里的电脑再次确认了一次,也是IE8,没有出现问题,看来是公司电脑的问题,但不明白为什么看原来的VML没有问题。。。