灌水青年..

使用PSPad开发PHP之收藏Snippet(之一)

上一篇 / 下一篇  2007-11-14 22:57:12

VS和ZEND有的功能PSPad也有,速度要比前者快的多,而且你也可以修改添加插件,使用vbscipt/js,而且它是免费的PHPChina 开源社区门户Q4s%G-|#vHLy
这一点是UltraEdit/EditPlus永远也赶不上的地方PHPChina 开源社区门户*zA!y7k q#Jo
今天要介绍的是一个Snippets插件,安装之后,你可以将选中的代码保存起来,下次再用时,只需要按下快捷键即可插入
1h^p#h?!\i.k0PHPChina 开源社区门户B8d3C6W _9h9p#O.i
以下是我今天收集的代码段,看后要顶,请补充,共享...PHPChina 开源社区门户*[jh u%R h}
function dhtmlspecialchars($string) {PHPChina 开源社区门户#|.DIq%t
    if(is_array($string)) {
'j a5Fh W+}s0        foreach($string as $key => $val) {PHPChina 开源社区门户"F$G[1R/?J
            $string[$key] = dhtmlspecialchars($val);PHPChina 开源社区门户{Z+iq`z#}:e+z0]y
        }PHPChina 开源社区门户d8YD-xd SjU
    } else {
/Tt MX X'QN0        $string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1',
N+\+j#Mr&`fP0        str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $string));PHPChina 开源社区门户A7h}X6oc:O
    }
3P#}!wM Y6J KW~0    return $string;PHPChina 开源社区门户+j2BN5j{(z
    
/B5|y&Gwu}0g0    function getClientIP()
R@X:r"xq6Q0{PHPChina 开源社区门户0K1g%ej Bx
    $onlineip = '';
_5uCM0o ?L0    if(getenv('HTTP_CLIENT_IP')) {
$V.Z1vhC'br0        $onlineip = getenv('HTTP_CLIENT_IP');
,D.gGP8L*\6Xk3S0    } elseif(getenv('HTTP_X_FORWARDED_FOR')) {
f1@H oN_3a0        list($onlineip) = explode(',', getenv('HTTP_X_FORWARDED_FOR'));
l(?7b'Y~X(~0    } elseif(getenv('REMOTE_ADDR')) {PHPChina 开源社区门户&Eh'B%Qe
        $onlineip = getenv('REMOTE_ADDR');PHPChina 开源社区门户#}9sV R-se
    } else {PHPChina 开源社区门户${ ?r%H{*q
        $onlineip = $_SERVER['REMOTE_ADDR'];PHPChina 开源社区门户U-z7Q$pUSh'Vn
    }
;Q{I:wQ+y0    return $onlineip;
G8U2w8Qq2]+k{8lfr]0}
Rr0Ro"C0
9q {D s:w L&qkn0Gif验证码PHPChina 开源社区门户v-VSuAY$u
PHPChina 开源社区门户 Ay`0fKl
<?phpPHPChina 开源社区门户.EW#oZnf0}$O
    ob_start(); PHPChina 开源社区门户z+]/n sG7j-j1zv
    session_start();PHPChina 开源社区门户RQ+J D)@8VT)c
    $rands = rand(1000,9999);PHPChina 开源社区门户 `@+mrbF&DV)M
    header("Content-type: image/gif");PHPChina 开源社区门户(m)h~;v!~mF
    $_SESSION['reg_num_check'] = $rands;
s)tziP x|%Yi4h0    $im = @imagecreate(40, 15);PHPChina 开源社区门户4W TM$caO u a
    imagecolorallocate($im, 240, 240, 240);PHPChina 开源社区门户[c`!~Df_Ee
    $loc = 2;PHPChina 开源社区门户 ao8C g#y\Ok
    $color1=imagecolorallocate($im, 0, 0, 0);
,My3@!| H]u0    for($i=0;$i<4;$i++){
l]+{XQK%f0        $color=imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));PHPChina 开源社区门户4~(A$qR*i
        imagestring($im, 4, ($loc+1), 1, substr($rands,$i,1), $color1);
QS:Ei Y g0        imagestring($im, 4, $loc, 0, substr($rands,$i,1), $color);
H5rDE*y0        $loc += 9;
(V$@"z+jXr2W r'z7Q0    }
]d)w*~#dg0    Imagegif($im);
0`X#j \3Gq+NG0    imagedestroy($im);
{/}#A V2d0    ob_end_flush();
^x}:x ^9Y\/D0?>
[!A%FnM/X0PHPChina 开源社区门户)gO*f+x6yWr
PHPChina 开源社区门户 K&Ae*ZT(gyP
    insert语句构造PHPChina 开源社区门户3? Z!x@0mV
   PHPChina 开源社区门户(S8e[kW
        function insert( $p_table, $p_values )PHPChina 开源社区门户u$]:}*n;q? m0}D ^%D
    {
6a D,F ^8y}4?s Z gs5K0        foreach( $p_values as $key => $var )
}Brx {s0        {
Z ]w)L R&}9f0            $sql_add_sub_name.= " `".$key."` ,";PHPChina 开源社区门户!F/`B c%g
            $sql_add_var_name.= " '".str_replace("'","\'",$var)."' ,";
)mD[*qfP0        }
z|N4mM+I4u Y0        $sql_add_sub_name = substr( $sql_add_sub_name, 0, -1 );PHPChina 开源社区门户Cll6@ h2w
        $sql_add_var_name = substr( $sql_add_var_name, 0, -1 );
*C|!p6lG-Uz0k0
$E^'_NN0        $real_sql = "INSERT INTO ".$p_table." (".$sql_add_sub_name.") VALUES (".$sql_add_var_name.")";PHPChina 开源社区门户b/xE1f!k
        return $this->query( $real_sql );
dmSj|7ou0    }PHPChina 开源社区门户2H4v)C+i%y%XUF
   PHPChina 开源社区门户7K)Z3DD t)U
   PHPChina 开源社区门户/]&wuh1B
   
@'P&V~(R5?#X |G0   
(SI?Q*t/v0    //循环创建路径
"e"L ZfD7O4p?-|0   PHPChina 开源社区门户Ya"]DZ#k0e(zr
    public static function mDir($dir)
8[i3HQF.z&Y3i M0    {PHPChina 开源社区门户7X\!n'pWJ
        $isc=true;
Vs?;^G0        if(!is_dir($dir)){PHPChina 开源社区门户7M&s[SG c1gp
            PubFunction::mDir(dirname($dir));PHPChina 开源社区门户 YF5GA:a,q P2G j#s
            if(!mkdir($dir))$isc=false;PHPChina 开源社区门户n"E CY+W)lA"e?
        }return $isc;PHPChina 开源社区门户C2j q#Ce:{ B;^h0t
    }PHPChina 开源社区门户$E&t6\,}0j,RTr.z
   
-[;B ih1P9ImVd0   
9V6UkR/U$ilRd0   PHPChina 开源社区门户XE!W }~5_RCn
    php实现多态PHPChina 开源社区门户#[,{a"i`b}h'EE
    <?phpPHPChina 开源社区门户Q9B4?(@7d*UM
class BoardPHPChina 开源社区门户9`Qh4V0G
{PHPChina 开源社区门户%dg`6m[h4[}
    function niceDrawing($x)PHPChina 开源社区门户|,|9]-f)]gmD
    {PHPChina 开源社区门户 F Atr*p*bi7HA)f0A ^ b
    //假设这是Board类的一个方法
] ~ ^,~\ g&\#W{0        $x->draw();PHPChina 开源社区门户!h(E#N4kCIE
    }   PHPChina 开源社区门户R*E T| @fb
}PHPChina 开源社区门户p2[k,w_wy
abstract class ShapePHPChina 开源社区门户.A b2d;xU)G)p
{
-G"d(i B/g5y$l0   abstract function draw();  
p X2Oi q0}PHPChina 开源社区门户8X2k.dG ^Wx

&TG$W Q^ ISFg0class Circle extends Shape
uGUWr6e"XM%r0{PHPChina 开源社区门户 nPJf2hl_!~
    function draw()
B'VQdx }i)`(p-pr u n0    {PHPChina 开源社区门户9a5T2\$AC X E2A%hy
        echo "Cricle drawing";
.cB"@Pm O0    }
rb B/m2?2m_~_e0}PHPChina 开源社区门户 D8q)R:K1qw%Uc Xu
PHPChina 开源社区门户3m4u'E/H [ HpYs
class Rectangle extends ShapePHPChina 开源社区门户!l1]N*Q^6OJ
{
DiS.aL y0    function draw()PHPChina 开源社区门户;Vv|7e_V.bx d8[
    {
uA:y1y9gX:vj1X0        echo "Rectangle drawing";
:Z#W o/r(^H HF0    }PHPChina 开源社区门户.k \ ]o-T#d
}
`B7v,BC0PHPChina 开源社区门户;p/P8H#mV5cI
$board = new Board();PHPChina 开源社区门户 _ b1KQ.k/]
$obj = new Circle(3,187);
d$H? ~u'}G4k8J0$obj2 = new Rectangle(4,5);PHPChina 开源社区门户 M9lp};O3v'k
$board->niceDrawing($obj);
+Ci0wWO{R8f'n"U"[0//将调用Circle的draw方法PHPChina 开源社区门户a+WRLR!O
$board->niceDrawing($obj2);
Q ^%nI P.O0?>
mM%_DE`b6t"f0
7reAeI$Ju`.dh0PHPChina 开源社区门户5`.N8O:_8s+s%?
//PHP实现覆盖
~ _2o1mWF7M0class MyClass
y Ln:D"_8E)ew0{
u(D0yr3p"q0   function showConstant() {
4Fw,H1h }/u5pW#rp0        echo  "a";
HQ7gF!|&K&gz0    }PHPChina 开源社区门户d w4vXA]$m
}PHPChina 开源社区门户8D?8G"KV-y
PHPChina 开源社区门户#k UbT_a \X
class MyClassExt extends MyClassPHPChina 开源社区门户lC J3x){ t2q u
{
YN ^io0    function showConstant()
&i#u!Xe5L)K0    {
1[ ^/dy)i2]lt0        parent::showConstant();   PHPChina 开源社区门户@ q+kWc:PdE`
        echo "2";
C&bW n B#}0    }
1xb-m [!]0}PHPChina 开源社区门户&l6e+i1A Iq:|MO
$testclass = new MyClassExt();
%{n#S7o"EY'B!C0$testclass->showConstant();PHPChina 开源社区门户Xa^[j:_
PHPChina 开源社区门户 YY"o3Vj7aa kD7I

a8}t1z5jV%Fu0PHP实现重载
4jEpO1D+@3i%L Saf0<?php
N5|ca"X0class Myclass {PHPChina 开源社区门户tLUS'Gw+hz
function Myclass() {
;UDn#?G z'Q9Np4i0    $name="Myclass".func_num_args();
6w9FYv uEI u[x0    @$this->$name();PHPChina 开源社区门户U-xI1uN
//注意$this->name()一般是错误的,但是在这里$name是一个将被调用方法的名字PHPChina 开源社区门户 k_*nGF`2T"M
}
4e^&gX2J^9_{0function Myclass1($x)PHPChina 开源社区门户5D\/M B4Q(mRh'} l%O
{
$g hS2Q4v|0    echo "class1";
^ DC{ P'AHe0}PHPChina 开源社区门户5C[S|hH2K[B
function Myclass2($x,$y)
ACjt \[u0{PHPChina 开源社区门户+Eo@(ku$j6Z0b8?
    echo "class2";PHPChina 开源社区门户c0u\?feD?
}PHPChina 开源社区门户 i!hSJ~U#C
PHPChina 开源社区门户+~w3I XP {R
}PHPChina 开源社区门户^a O;z2MR!Ax
//通过在类中的额外的处理,使用这个类对用户是透明的:PHPChina 开源社区门户(r3@YR7t]/]|7Y
$obj1=new Myclass('1'); //将调用Myclass1
+h;X0{8z L4U#{1S0$obj2=new Myclass('1','2'); //将调用Myclass2PHPChina 开源社区门户B*f(ze.^7Y
?>
eu Uo3B2{0PHPChina 开源社区门户.\xy"iLo*UT,f8T
将数组序列化成对象保存入cookie
*x{;g#c8]3HoD@}0$user_array = array(
^Kea+s.v0     'name' => '张三',
_$_d]c&t.O8uH0     'age' => '55',PHPChina 开源社区门户 Kt M&?X9vlS
     'sex' => '男'PHPChina 开源社区门户5?1y$S,W\
     );PHPChina 开源社区门户tq6l~)z w`
setcookie('userinfo', base64_encode(serialize($user_array)));
#bLp,R Q"G+J+F9JE'^)a0PHPChina 开源社区门户9s7G2Qa$Uh
$user_array = unserialize(base64_decode ($_COOKIE['userinfo']));
^:ckS M9k0var_dump($user_array); PHPChina 开源社区门户~]U5K v;q8Z
PHPChina 开源社区门户9}.h7T~4c L5H%@&n

\8U5q$tu8J%VD0G!Wv0
9Kp2GqUX*f0//代理类实现PHPChina 开源社区门户B:J Zg#h4mh m C

#d{9o E^7L,gL0class Proxy
}k HC7{"Y?0{
yTLoWK0private $object;PHPChina 开源社区门户4Q:d|V5N4Zv-^+@\4F
function __call($name, $params) {
-pEP+P2Y u0    if ( isset($this->object) )
8M+Q(j3Ij6N3D0    {
,g&a XLY A2`@Z1D0O:q0        if ( method_exists($this->object, $name) )PHPChina 开源社区门户0^\q \5X2gJ.vkn
        {
@#zV7L^FX@v0            return call_user_func_array(array($this->object, $name), $params);
5n4AhMK0T n,Nb0        } else {PHPChina 开源社区门户kx&x/U'Sq
            return "method not exists.";PHPChina 开源社区门户.H)xwGX'rdC
        }PHPChina 开源社区门户FF@ I9{"]+qd
    }PHPChina 开源社区门户)Z+gO)U'w!M3|?
}PHPChina 开源社区门户.eE0Oq6M
function __construct($object)PHPChina 开源社区门户;t0D8\N8WG7_.I8hD
{PHPChina 开源社区门户w0}.n _:H8|N
$this->object = $object;
e-]IU/r)pP0}PHPChina 开源社区门户z+n t1JW6h2@ hJ6wC0q
}PHPChina 开源社区门户$L~?8?}IC!j.saH
PHPChina 开源社区门户 efI3q-c$T |R
class Hoge
z%t2_ n ](p0{
Ca+R o;^"^A2w1V0function add($var1, $var2)
^VK|;@"a0{
@+xT5p/W+E0    return $var1 + $var2;
c-|Nh;r T0}
0gDD/V:A0F0}PHPChina 开源社区门户A3Y1N d(v/Is8AV
PHPChina 开源社区门户lLM,Fn$j2Q:]O.J
$p = new Proxy(new Hoge);PHPChina 开源社区门户:Zv Lo,h{2XE)r,R
PHPChina 开源社区门户d ^}b6S
$result = $p->add(1, 2);PHPChina 开源社区门户'Vc \_]
echo "result: $result".'<br>';;
g\]S!Cps P2Y0
p'n&j }Z5a0$result = $p->sub(5, 3);
*Uj0V D8bm Hx0echo "result: $result".'<br>';PHPChina 开源社区门户A[*\Q`l

A6wjHl"U0 

TAG: PHP PSPad Snippet 代码段 修煉成果

引用 删除 Guest   /   2008-05-25 22:27:00
www.xingchenbian33.cn
www.meinv880.cn
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

数据统计

  • 访问量: 12733
  • 日志数: 102
  • 图片数: 3
  • 书签数: 15
  • 建立时间: 2007-05-19
  • 更新时间: 2007-11-22

RSS订阅

Open Toolbar