wb's profileηщъBlogListsNetwork Tools Help

wb N

Location
Interests
这家伙很懒.什么多没留下
This person's network is empty (or maybe they're keeping it private).

ηщъ

流水空空....

Catch

September 01

决定把空间转移了,放到个人空间去了

空人空间 转移了,转到 http://www.33505.net  ,MSN的空间太慢,自主性太差,最主要的是,BAIDU,GOOGLE不收录.让这里荒芜,也许10年后再回到这里,夕阳西下,放眼杂草丛生,是否还能回忆起什么.
August 24

常用表单验证类,验证EMAIL地址,电话号码等

//常用表单验证类
class class_post
{
 //验证是否为指定长度的字母/数字组合
 function fun_text1($num1,$num2,$str)
 {
    Return (preg_match("/^[a-zA-Z0-9]{".$num1.",".$num2."}$/",$str))?true:false;
 }

 //验证是否为指定长度数字
 function fun_text2($num1,$num2,$str)
 {
    return (preg_match("/^[0-9]{".$num1.",".$num2."}$/i",$str))?true:false;
 } 
 //验证是否为指定长度汉字
 function fun_font($num1,$num2,$str)
 {
 // preg_match("/^[\xa0-\xff]{1,4}$/", $string);
    return (preg_match("/^([\x81-\xfe][\x40-\xfe]){".$num1.",".$num2."}$/",$str))?true:false;
 }
 //验证身份证号码
 function fun_status($str)
 {
    return (preg_match('/(^([\d]{15}|[\d]{18}|[\d]{17}x)$)/',$str))?true:false;
 }

 //验证邮件地址
 function fun_email($str){
    return (preg_match('/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$/',$str))?true:false;
 }
 //验证电话号码
 function fun_phone($str)
 {
  return (preg_match("/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/",$str))?true:false;
 }
 //验证邮编
 function fun_zip($str)
 {
  return (preg_match("/^[1-9]\d{5}$/",$str))?true:false;
 }
 //验证url地址
 function fun_url($str)
 {
  return (preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/",$str))?true:false;
 } 

 // 数据入库 转义 特殊字符 传入值可为字符串 或 一维数组
 function data_join(&$data)
 {
  if(get_magic_quotes_gpc() == false)
  {
   if (is_array($data))
   {
    foreach ($data as $k => $v)
    {
     $data[$k] = addslashes($v);
    }
   }
   else
   {
    $data = addslashes($data);
   }
  }
  Return $data;
 }

 // 数据出库 还原 特殊字符 传入值可为字符串 或 一/二维数组
 function data_revert(&$data)
 {
  if (is_array($data))
  {
   foreach ($data as $k1 => $v1)
   {
    if (is_array($v1))
    {
     foreach ($v1 as $k2 => $v2)
     {
      $data[$k1][$k2] = stripslashes($v2);
     }
    }
    else
    {
     $data[$k1] = stripslashes($v1);
    }
   }
  }
  else
  {
   $data = stripslashes($data);
  }
  Return $data;
 }

 // 数据显示 还原 数据格式 主要用于内容输出 传入值可为字符串 或 一/二维数组
 // 执行此方法前应先data_revert(),表单内容无须此还原
 function data_show(&$data)
 {
  if (is_array($data))
  {
   foreach ($data as $k1 => $v1)
   {
    if (is_array($v1))
    {
     foreach ($v1 as $k2 => $v2)
     {
      $data[$k1][$k2]=nl2br(htmlspecialchars($data[$k1][$k2]));
      $data[$k1][$k2]=str_replace(" ","&nbsp;",$data[$k1][$k2]);
      $data[$k1][$k2]=str_replace("\n","<br>\n",$data[$k1][$k2]);
     }
    }
    else
    {
     $data[$k1]=nl2br(htmlspecialchars($data[$k1]));
     $data[$k1]=str_replace(" ","&nbsp;",$data[$k1]);
     $data[$k1]=str_replace("\n","<br>\n",$data[$k1]);
    }
   }
  }
  else
  {
   $data=nl2br(htmlspecialchars($data));
   $data=str_replace(" ","&nbsp;",$data);
   $data=str_replace("\n","<br>\n",$data);
  }
  Return $data;
 }
 }

 
August 20

php无乱码截取中文字符的函数

当用 substr 截取中文字符的时候会出现乱码,当然你如果装了 mb 扩展 用 mb_substr截取就不会出现这种问题,如果你用的是虚拟主机,主机上又没装 mb扩展的话,你可以用下面的函数截取
 
# Cut chinese string into appointed length
 # @param [string] string need deal
 # @param [start]  position to cut from
 # @param [length] length to cut
 # @return string
 function GBsubstr($string, $start, $length) {
  if(strlen($string)>$length){
   $str=null;
   $len=$start+$length;
   for($i=$start;$i<$len;$i++){
    if(ord(substr($string,$i,1))>0xa0){
     $str.=substr($string,$i,2);
     $i++;
    }else{
     $str.=substr($string,$i,1);
    }
   }
   return  $str.'...';
  }else{
   return $string;
  }
 }
 
 
August 08

MagickWand fro php功能齐全的一个例子

<?php

/*

* Description: The following script demonstrates the inate capabilities of
*              MagickWand for PHP by creating an animated GIF.
*              MagickWand for PHP capabilities used:
*              1) vector drawing (shapes, text, colors)
*              2) default font
*              3) unique color model
*              4) addition of random noise
*              5) several special effects methods
*              6) setting of single frame display time
*              7) and much more...
*/

/* General Settings */

$noise_frames = 5;
$noise_delay = 20;

$cnt_down_start = 3;
$cnt_down_delay = 50;
$width = 140;
$height = 70;

$x_int = $width / 10;
$y_int = $height / 10;
$x1 = $x_int;
$y1 = $y_int;
$x2 = $width - $x_int;
$y2 = $height - $y_int;
$x_radius = $y_radius = 10;

$font_size = 30;

$swirl_deg_start = 0;
$swirl_deg_end = 360; /* The maximum degree amount that the last countdown
                         frame will be swirled */
$swirl_deg_int = 60; /* The swirl loop degree increment value */
$swirl_delay = 10; /* The length of time (in hundredth's of a second) that
                      each swirled frame will be displayed */

$num_morph_frames = 5; /* The number of intermediary frames between images to
                          be morphed */
$morph_delay = 20; /* The length of time (in hundredth's of a second) that
                      each morphed frame will be displayed */

$logo = 'MagickWand for PHP'; /* The 1st string to be displayed */

$welcome_msg = 'The future awaits...'; /* The 2nd string to be displayed */

$mgck_wnd = NewMagickWand(); /* Create a new MagickWand resource -- "holds"
                                the images */

$bg_color= NewPixelWand(); /* Creates a new PixelWand resource -- contains
                              information on an individual unit of color;
                              opaque black by default */

$white = NewPixelWand('white'); /* Does the same as above, except that the
                                   PixelWand's color is set to white */

$pxl_wnd = NewPixelWand();

$drw_wnd = NewDrawingWand(); /* Creates a new DrawingWand resource -- holds
                                vector drawing commands */

$txt_wnd = NewDrawingWand();

/*
The following loop iterates $noise_frames times, doing the following each
time:
   1) Creates a new image using MagickNewImage()
   2) Adds MW_LaplacianNoise type random noise to the newly created image
   3) Sets the amount of time the image is displayed to $noise_delay
      hundredths of a second, using MagickSetImageDelay()

The user function checkWandError() checks the return type of API functions for
explicit FALSE (via the "===" operator), which indicates an error occurred.
*/
for ($i = 0; $i < $noise_frames; $i++) {

    checkWandError(MagickNewImage($mgck_wnd, $width, $height, $bg_color), $mgck_wnd, __LINE__);

    checkWandError(MagickAddNoiseImage($mgck_wnd, MW_LaplacianNoise), $mgck_wnd, __LINE__);

    checkWandError(MagickSetImageDelay($mgck_wnd, $noise_delay), $mgck_wnd, __LINE__);
}

/* Retrieve the current image from $mgck_wnd in a new MagickWand, and assign
   it to $pre_morph_wnd.
*/
$pre_morph_wnd =& checkWandError(MagickGetImage($mgck_wnd), $mgck_wnd, __LINE__);

/* Set variables to random values between 0 and 255, for use in an
   ImageMagick color string RGB triple (e.g. rgb(255, 255, 255) == white).
*/
$red   = mt_rand(0, 255);
$green = mt_rand(0, 255);
$blue  = mt_rand(0, 255);

/* Use color values from above to form an ImageMagick color string RGB triple,
   and set the $pxl_wnd PixelWand to that color.
*/
checkWandError(PixelSetColor($pxl_wnd, "rgb($red, $green, $blue)"), $pxl_wnd, __LINE__);

/* Set the fill color (the color in which shapes and text will be drawn), to
   $pxl_wnd's color.
*/
DrawSetFillColor($drw_wnd, $pxl_wnd);

/* Add a command to draw a rounded rectangle to the $drw_wnd DrawingWand
   from point ($x1, $y1), the top-left corner of the bounding rectangle
   to ($x2, $y2), (the bottom right corner), with a corner x-axis radius of
   $x_radius, and a corner y-axis radius of $y_radius.
*/
DrawRoundRectangle($drw_wnd, $x1, $y1, $x2, $y2, $x_radius, $y_radius);

/* Create a new image, in $pre_morph_wnd, of $width * $height area, with
   $bg_color (currently a black PixelWand resource) background color, set
   it's display time to $morph_delay, and draw the $drw_wnd DrawingWand on
   the new image.
*/
drawNewImageSetDelay($pre_morph_wnd, $drw_wnd, $width, $height, $bg_color, $morph_delay, __LINE__);

/* Morph the images in $pre_morph_wnd, set their displaytime, and and add
   them to $mgck_wnd.
*/
addMorphedImages($mgck_wnd, $pre_morph_wnd, $num_morph_frames, $morph_delay, __LINE__);

/* Free the resources associated with $pre_morph_wnd, since it is no longer
   needed.
*/
DestroyMagickWand($pre_morph_wnd);

/* Set the current active image, in $mgck_wnd's image squence, to the last image.
*/
MagickSetLastIterator($mgck_wnd);

/* Starting from $i = $cnt_down_start, (with $i being decreased by one at each
   iteration's end), and continuing while $i > 0, and the widths and heights of
   the rounded rectangles to be drawn are greater than the amounts by which
   their sizes are decreased through each iteration,
*/
for ($i = $cnt_down_start; $i > 0 && ($x2 - $x1) >= $x_int && ($y2 - $y1) >= $y_int; $i--) {

    /* Set the PixelWand $pxl_wnd's color to that of the ImageMagick color
       string RGB triple "rgb($red, $green, $blue)", where $red, $green, and
       $blue are numbers between 0 and 255, inclusive.
    */
    checkWandError(PixelSetColor($pxl_wnd, "rgb($red, $green, $blue)"), $pxl_wnd, __LINE__);

    /* Add commands to draw a $pxl_wnd colored rounded rectangle to $drw_wnd */
    DrawSetFillColor($drw_wnd, $pxl_wnd);
    DrawRoundRectangle($drw_wnd, $x1, $y1, $x2, $y2, $x_radius, $y_radius);

    $red   = mt_rand(0, 255);
    $green = mt_rand(0, 255);
    $blue  = mt_rand(0, 255);

    /* Decrease the size of the next rounded rectange to be drawn */
    $x1 += $x_int;
    $y1 += $y_int;

    $x2 -= $x_int;
    $y2 -= $y_int;

    /* Create a new image in $mgck_wnd, and draw $drw_wnd on it */
    drawNewImageSetDelay($mgck_wnd, $drw_wnd, $width, $height, $bg_color, $cnt_down_delay, __LINE__);

    /* Add commands to draw $i in $white colored text $font_size, horizontally
       and vertically centered at relative point (0, 0), (see function
       definition for details), to the $txt_wnd DrawingWand.
    */
    addText($txt_wnd, $white, $font_size, $i);

    /* Draw $txt_wnd on the just created image in the $mgck_wnd MagickWand */
    checkWandError(MagickDrawImage($mgck_wnd, $txt_wnd), $mgck_wnd, __LINE__);

    /* Clear the $txt_wnd DrawingWand of any accumulated commands, and reset the
       settings it contains to their defaults.
    */
    ClearDrawingWand($txt_wnd);
}

/* Add commands to draw $i, (which now holds a value that is 1 less than the
   last $i value drwan in the loop above), in $white at $font_size, to the
   $drw_wnd DrawingWand
*/
addText($drw_wnd, $white, $font_size, $i);

/* Draw $drw_wnd on a new image in $mgck_wnd */
drawNewImageSetDelay($mgck_wnd, $drw_wnd, $width, $height, $bg_color, $swirl_delay, __LINE__);

/* The following loop creates a set of images which, when set as animation
   frames, creates a sort of hurricane effect.
  
   Starting at $swirl_deg = $swirl_deg_start degrees, and increasing
   $swirl_deg by $swirl_deg_int degrees as long as $swirl_deg is less than or
   equal to $swirl_deg_end, ...
*/
for ($swirl_deg = $swirl_deg_start; $swirl_deg <= $swirl_deg_end; $swirl_deg += $swirl_deg_int) {

    /* create a new image, draw $drw_wnd on it, set its display time to
       $swirl_delay hundredths of a second, ...
    */
    drawNewImageSetDelay($mgck_wnd, $drw_wnd, $width, $height, $bg_color, $swirl_delay, __LINE__);

    /* and perform the swirl special effect on it at $swirl_deg. */
    checkWandError(MagickSwirlImage($mgck_wnd, $swirl_deg), $mgck_wnd, __LINE__);
}

/* Following loop ensures that $font_size is */
while (TRUE) {

    /* Set the text font size used by $txt_wnd to $font_size */
    DrawSetFontSize($txt_wnd, $font_size);

    /* MagickGetStringWidth() returns the width of the specified strings
       ($logo and $welcome_msg), when they are drawn with the settings (font,
       font size, stroke, etc.) of the specified DrawingWand, $txt_wnd.
    */
    $logo_width =& checkWandError(MagickGetStringWidth($mgck_wnd, $txt_wnd, $logo), $mgck_wnd, __LINE__);
    $welcome_msg_width =& checkWandError(MagickGetStringWidth($mgck_wnd, $txt_wnd, $welcome_msg), $mgck_wnd, __LINE__);

    /* If the widths of both strings are within the acceptable limits, end
       the loop.
    */
    if ($logo_width < $width && $welcome_msg_width < $width) {
        break;
    }

    /* Otherwise, decrement the $font_size */
    $font_size--;
}

/* Retrieve the current image from $mgck_wnd in a new MagickWand, and assign
   it to $pre_morph_wnd.
*/
$pre_morph_wnd =& checkWandError(MagickGetImage($mgck_wnd), $mgck_wnd, __LINE__);

/* Add commands to the $txt_wnd DrawingWand to draw the $logo string in $white
   at $font_size, then draw $txt_wnd on a new image in $pre_morph_wnd.
*/
addText($txt_wnd, $white, $font_size, $logo);
drawNewImage($pre_morph_wnd, $txt_wnd, $width, $height, $bg_color, __LINE__);

/* Clear $txt_wnd's command list and reset its settings */
ClearDrawingWand($txt_wnd);

/* Draw $welcome_msg in $white at $font_size on another new image in
   $pre_morph_wnd.
*/
addText($txt_wnd, $white, $font_size, $welcome_msg);
drawNewImage($pre_morph_wnd, $txt_wnd, $width, $height, $bg_color, __LINE__);

/* Add the first image in $mgck_wnd to $pre_morph_wnd. */
MagickSetFirstIterator($mgck_wnd);
checkWandError(MagickAddImage($pre_morph_wnd, $mgck_wnd), $pre_morph_wnd, __LINE__);

/* Morph the images in $pre_morph_wnd and add them to the end of $mgck_wnd's
   image sequence.
*/
addMorphedImages($mgck_wnd, $pre_morph_wnd, $num_morph_frames, $morph_delay, __LINE__);

/* Free the resources associated with $pre_morph_wnd, $drw_wnd and $txt_wnd,
   since they are no longer needed.
*/
DestroymagickWand($pre_morph_wnd);
DestroyDrawingWand($drw_wnd);
DestroyDrawingWand($txt_wnd);

/* Sets the output format of $mgck_wnd's image sequence to GIF */
checkWandError(MagickSetFormat($mgck_wnd, 'GIF'), $mgck_wnd, __LINE__);

/* Retrieves the mime-type associated with $mgck_wnd's image sequence, and
   outputs it in a Content-Type header.
*/
header('Content-Type: ' . MagickGetMimeType($mgck_wnd));

/* Outputs $mgck_wnd's image sequence as a BLOB (Binary Large Object) */
MagickEchoImagesBlob($mgck_wnd);

/* Free the resources associated with $mgck_wnd */
DestroymagickWand($mgck_wnd);


function &checkWandError(&$result, $wand, $line) {

    if ($result === FALSE && WandHasException($wand)) {
        echo '<pre>An error occurred on line ', $line, ': ', WandGetExceptionString($wand), '</pre>';
        exit();
    }

    return $result;
}

/**
* Function addText() performs several operations on the DrawingWand
* $drw_wnd:
*    1) sets the fill color (the color in which shapes, text, etc. will be
*       drawn) from the PixelWand (or Imagemagick color string) $pxl_wnd with
*       DrawSetFillColor()
*    2) sets the font size of text to be drawn to $font_size, using
*       DrawSetFontSize()
*    3) sets the position where text will be drawn with DrawSetGravity();
*       position is set to MW_CenterGravity by default, which automatically
*       centers text horizontally and vertically
*    4) sets text to be drawn later to $text, which will be drawn at
*       coordinate ($x, $y), (relative to the position indicated by
*       $gravity), with DrawAnnotation()
*/
function addText($drw_wnd, $pxl_wnd, $font_size, $text, $gravity = MW_CenterGravity, $x = 0, $y = 0) {

    /* Set the color used to draw shapes and text with $drw_wnd to $pxl_wnd's
       color
    */
    DrawSetFillColor($drw_wnd, $pxl_wnd);

    /* Set the text font size used by $drw_wnd to $font_size */
    DrawSetFontSize($drw_wnd, $font_size);

    /* Set $drw_wnd text gravity (automatic text positioning setting), to
       $gravity
    */
    DrawSetGravity($drw_wnd, $gravity);

    /* Add a command to the $drw_wnd DrawingWand to draw the $text string at
       point ($x, $y) (relative to $drw_wnd's gravity setting).
    */
    DrawAnnotation($drw_wnd, $x, $y, $text);
}

/**
* Function drawNewImage() creates a new image, using MagickNewImage(), of
* $width * $height area, filled with $bg_color (a PixelWand, or ImageMagick
* color string) color.
* @return void
*/
function drawNewImage($mgck_wnd, $drw_wnd, $width, $height, $bg_color, $line) {

    $line = 'program line '.$line.', function line ';

    checkWandError(MagickNewImage($mgck_wnd, $width, $height, $bg_color), $mgck_wnd, $line.__LINE__);
    checkWandError(MagickDrawImage($mgck_wnd, $drw_wnd), $mgck_wnd, $line.__LINE__);
}

/**
* Function drawNewImageSetDelay() calls drawNewImage() to create a new
* image, of $width * $height area, filled with $bg_color color, drawn on by
* DrawingWand $drw_wnd.
*
* @return void
*/
function drawNewImageSetDelay($mgck_wnd, $drw_wnd, $width, $height, $bg_color, $delay, $line) {

    drawNewImage($mgck_wnd, $drw_wnd, $width, $height, $bg_color, $line);

    $line = 'program line '.$line.', function line ';

    checkWandError(MagickSetImageDelay($mgck_wnd, $delay), $mgck_wnd, $line.__LINE__);
}

/**
* Function addMorphedImages() morphs the images in $pre_morph_wnd, with
* $num_morph_frames intermediary frames. The new sequence's images are then
* set to display for $morph_delay 100th's of a second, and then added to the
* end of $mgck_wnd's image list.
* @return void
*/
function addMorphedImages($mgck_wnd, $pre_morph_wnd, $num_morph_frames, $morph_delay, $line) {

    $line = 'program line '.$line.', function line ';

    /* Set the current active image in the $mgck_wnd MagickWand to the first
       image in its image list
    */
    MagickSetFirstIterator($pre_morph_wnd);

    /* Perform the morph special effect on $pre_morph_wnd and assign the result
       to $morph_wnd
    */
    $morph_wnd =& checkWandError(MagickMorphImages($pre_morph_wnd, $num_morph_frames), $pre_morph_wnd, $line.__LINE__);

    /* Set the current active image in the $morph_wnd MagickWand to the first
       image in its image list and remove it.
    */
    MagickSetFirstIterator($morph_wnd);
    checkWandError(MagickRemoveImage($morph_wnd), $morph_wnd, $line.__LINE__);

    /* Set the current active image in the $morph_wnd MagickWand to the last
       image in its image list and remove it.
    */
    MagickSetLastIterator($morph_wnd);
    checkWandError(MagickRemoveImage($morph_wnd), $morph_wnd, $line.__LINE__);

    /* Reset $morph_wnd's image list iterator; this has the effect that the
       next call to MagickNextImage($morph_wnd) sets $morph_wnd's current
       active image index to 0, i.e., to the first image.

       Contrast this behavior to MagickSetFirstIterator()'s, which sets the
       current active image's index to 0, causing the next call to
       MagickNextImage() to actually set the image index to 1, i.e., the
       second image in the MagickWand in question.

       This is an important distinction -- be careful.
    */
    MagickResetIterator($morph_wnd);
    while (MagickNextImage($morph_wnd)) {
        /*
           Set the length of time the current active image is displayed to
           $morph_delay hundredths of a second.
        */
        checkWandError(MagickSetImageDelay($morph_wnd, $morph_delay), $morph_wnd, $line.__LINE__);
    }

    MagickSetLastIterator($morph_wnd);

    /* Add the images in $morph_wnd to the end of $mgck_wnd */
    MagickSetLastIterator($mgck_wnd);
    checkWandError(MagickAddImages($mgck_wnd, $morph_wnd), $mgck_wnd, $line.__LINE__);

    DestroymagickWand($morph_wnd);
}

?>


 

August 07

用一个DIV锁定页面

<script>
function unlocked()
{
//oDiv=document.getElementById("bgDiv");
//document.body.removeChild(oDiv);//删除
oDiv=document.getElementById("locked");
oDiv.style.display='none';
}
function locked()
{
oDiv=document.getElementById("locked");
oDiv.style.display='block';
 
/* 
var sWidth,sHeight;
sWidth=screen.width;
sHeight=screen.height;
mleft=0;
bgObj=parent.document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.setAttribute("align","center");
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.background="#cccccc";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity="0.8";
bgObj.style.left=mleft+"px";
bgObj.style.width=1003 + "px";
bgObj.style.height=570 + "px";
bgObj.style.zIndex = "1000";
parent.document.body.appendChild(bgObj);
bgDiv.attachEvent('onclick',unlocked);
*/
}
</script>
<table width="200" border="1">
  <tr>
    <td><span  onclick="locked()">锁定</span></td>
  </tr>
</table>
<div id='locked'    onclick='unlocked()' style='position:absolute;width:1000px;height:580px;left:0;top:0;z-index:50;filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=30,finishOpacity=75);background:#000; display:none;' ></div>
 
 

php

No list items have been added yet.
No list items have been added yet.
No list items have been added yet.