文件上传类--upload.php

<?php

/**
 * 我的文件上传类
 *
 * 未完成的功能:
 * 1.对目标目录是否存在的判断
 * 2.如果上传时出现重名,自动重命名
 *
 * @author M.Q. <[url]www.mengqi.net[/url]>
 */
class upload
{
    /**
     * 上传文件的信息,此值由构造函数取得,如果上传文件失败或出错或未上传,则此值为false
     *
     * @var array
     */
    private $file = false;
   
  
    /**
     * 构造函数:取得上传文件的信息
     *
     * 如果在上传文件的工程中发生错误,那么出错的文件不会放在结果中返回,结果中的文件都是可用的
     *
     * @param string $tag form表单中<input>标签中name属性的值,例<input name="p" type="file">
     *
     * 例1,上传单个文件:
     * <input name="upfile" type="file">
     *
     * 例2,上传多个文件:
     * <input name="upfile[]" type="file">
     * <input name="upfile[]" type="file">
     *
     * 结果(保存在$file变量中)如下:
     *
     * array(
     * [0] => array(
     *      ''name''      => ''abc.txt''
     *      ''type''      => ''text/plain’
     *      ''tmp_name''  => ''/tmp/phpgxecCb''
     *      ''error''     => 0
     *      ''size''      => 62
     *      )
     * [1] => array(
     *      ''name''&n

<

阅读全文

php给图片加水印六

<?

 function _countMaskPos()
    {
        if($this->_isFull())
        {
            switch($this->mask_position)
            {
                case 1:
                    // 左上
                    $this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
                    $this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
                    break;
 
                case 2:
                    // 左下
                    $this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
                    $this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
                    break;
 
                case 3:
                    // 右上
                    $this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
                    $this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
                    break;
 
                case 4:
                    // 右下
                    $this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
                    $this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
                    break;
 
                default:
                    // 默认将水印放到右下,偏移指定像素
                    $this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
                    $this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
                    break;
            }
        }
        else
        {
            switch($this->mask_position)
            {
                case 1:
                    // 左上
                    $this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
                    $this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
                    break;
 
                case 2:
                    // 左下
                    $this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
                    $this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
                    break;
 
                case 3:
                    // 右上
                    $this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
                    $this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
                    break;
 
                case 4:
                    // 右下
                    $this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
                    $this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
                    break;
 
                default:
                    // 默认将水印放到右下,偏移指定像素
                    $this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
                    $this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
                    break;
            }
        }
    }
 
    /**
     * 设置字体信息
     */
    function _setFontInfo()
    {
        if(is_numeric($this->font))
        {
            $this->font_w  = imagefontwidth($this->font);
            $this->font_h  = imagefontheight($this->font);
 
            // 计算水印字体所占宽高
            $word_length   = strlen($this->mask_word);
            $this->mask_w  = $this->font_w*$word_length;
            $this->mask_h  = $this->font_h;
        }
        else
        {
            $arr = imagettfbbox ($this->font_size,0, $this->font,$this->mask_word);
            $this->mask_w  = abs($arr[0] - $arr[2]);
            $this->mask_h  = abs($arr[7] - $arr[1]);
        }
    }
 
    /**
     * 设置新图尺寸
     *
     * @param    integer     $img_w   目标宽度
     * @param    integer     $img_h   目标高度
     */
    function _setNewImgSize($img_w, $img_h=null)
    {
        $num = func_num_args();
        if(1 == $num)
        {
            $this->img_scale = $img_w;// 宽度作为比例
            $this->fill_w = round($this->src_w * $this->img_scale / 100) - $this->img_border_size*2;
            $this->fill_h = round($this->src_h * $this->img_scale / 100) - $this->img_border_size*2;
 
            // 源文件起始坐标
            $this->src_x  = 0;
            $this->src_y  = 0;
            $this->copy_w = $this->src_w;
            $this->copy_h = $this->src_h;
 
            // 目标尺寸
            $this->dst_w   = $this->fill_w + $this->img_border_size*2;
            $this->dst_h   = $this->fill_h + $this->img_border_size*2;
        }
 
        if(2 == $num)
        {
            $fill_w   = (int)$img_w - $this->img_border_size*2;
            $fill_h   = (int)$img_h - $this->img_border_size*2;
            if($fill_w < 0 || $fill_h < 0)
            {
                die("图片边框过大,已超过了图片的宽度");
            }
            $rate_w = $this->src_w/$fill_w;
            $rate_h = $this->src_h/$fill_h;
 
            switch($this->cut_type)
            {
                case 0:
                    // 如果原图大于缩略图,产生缩小,否则不缩小
                    if($rate_w < 1 && $rate_h < 1)
                    {
                        $this->fill_w = (int)$this->src_w;
                        $this->fill_h = (int)$this->src_h;
                    }
                    else
                    {
                        if($rate_w >= $rate_h)
                        {
                            $this->fill_w = (int)$fill_w;
                            $this->fill_h = round($this->src_h/$rate_w);
                        }
                        else
                        {
                            $this->fill_w = round($this->src_w/$rate_h);
                            $this->fill_h = (int)$fill_h;
                        }
                    }
 
                    $this->src_x  = 0;
                    $this->src_y  = 0;
 
                    $this->copy_w = $this->src_w;
                    $this->copy_h = $this->src_h;
 
                    // 目标尺寸
                    $this->dst_w   = $this->fill_w + $this->img_border_size*2;
                    $this->dst_h   = $this->fill_h + $this->img_border_size*2 - 10 ;//补偿round误差 消除白边;
                    break;
 
                // 自动裁切
                case 1:
                    // 如果图片是缩小剪切才进行操作
                    if($rate_w >= 1 && $rate_h >=1)
                    {
                        if($this->src_w > $this->src_h)
                        {
                            $src_x = round($this->src_w-$this->src_h)/2;
                            $this->setSrcCutPosition($src_x, 0);
                            $this->setRectangleCut($fill_h, $fill_h);
 
                            $this->copy_w = $this->src_h;
                            $this->copy_h = $this->src_h;
                           
                        }
                        elseif($this->src_w < $this->src_h)
                        {
                            $src_y = round($this->src_h-$this->src_w)/2;
                            $this->setSrcCutPosition(0, $src_y);
                            $this->setRectangleCut($fill_w, $fill_h);
 
                            $this->copy_w = $this->src_w;
                            $this->copy_h = $this->src_w;
                        }
                        else
                        {
                            $this->setSrcCutPosition(0, 0);
                            $this->copy_w = $this->src_w;
                            $this->copy_h = $this->src_w;
                            $this->setRectangleCut($fill_w, $fill_h);
                        }
                    }
                    else
                    {
                        $this->setSrcCutPosition(0, 0);
                        $this->setRectangleCut($this->src_w, $this->src_h);
 
                        $this->copy_w = $this->src_w;
                        $this->copy_h = $this->src_h;
                    }
 
                    // 目标尺寸
                    $this->dst_w   = $this->fill_w + $this->img_border_size*2;
                    $this->dst_h   = $this->fill_h + $this->img_border_size*2;
                   
                    break;
 
                // 手工裁切
                case 2:
                    $this->copy_w = $this->fill_w;
                    $this->copy_h = $this->fill_h;
 
                    // 目标尺寸
                    $this->dst_w   = $this->fill_w + $this->img_border_size*2;
                    $this->dst_h   = $this->fill_h + $this->img_border_size*2;               
                   
                    break;
                default:
                    break;
 
            }
        }
 
        // 目标文件起始坐标
        $this->start_x = $this->img_border_size;
        $this->start_y = $this->img_border_size;
    }
 
    /**
     * 检查水印图是否大于生成后的图片宽高
     */
    function _isFull()
    {
        Return (   $this->mask_w + $this->mask_offset_x > $this->fill_w
                || $this->mask_h + $this->mask_offset_y > $this->fill_h)
                   ?true:false;
    }
 
    /**
     * 检查水印图是否超过原图
     */
    function _checkMaskValid()
    {
        if(    $this->mask_w + $this->mask_offset_x > $this->src_w
            || $this->mask_h + $this->mask_offset_y > $this->src_h)
        {
            die("水印图片尺寸大于原图,请缩小水印图");
        }
    }
 
    /**
     * 取得图片类型
     *
     * @param    string     $file_path    文件路径
     */
    function _getImgType($file_path)
    {
        $type_list = array("1"=>"gif","2"=>"jpg","3"=>"png","4"=>"swf","5" => "psd","6"=>"bmp","15"=>"wbmp");
        if(file_exists($file_path))
        {
            $img_info = @getimagesize ($file_path);
            if(isset($type_list[$img_info[2]]))
            {
                Return $type_list[$img_info[2]];
            }
        }
        else
        {
            die("文件不存在,不能取得文件类型!");
        }
    }
 
    /**
     * 检查图片类型是否合法,调用了array_key_exists函数,此函数要求
     * php版本大于4.1.0
     *
     * @param    string     $img_type    文件类型
     */
    function _checkValid($img_type)
    {
        if(!array_key_exists($img_type, $this->all_type))
        {
            Return false;
        }
    }
 
    /**
     * 按指定路径生成目录
     *
     * @param    string     $path    路径
     */
    function _mkdirs($path)
    {
        $adir = explode('/',$path);
        $dirlist = '';
        $rootdir = array_shift($adir);
        if(($rootdir!='.'||$rootdir!='..')&&!file_exists($rootdir))
        {
            @mkdir($rootdir);
        }
        foreach($adir as $key=>$val)
        {
            if($val!='.'&&$val!='..')
            {
                $dirlist .= "/".$val;
                $dirpath = $rootdir.$dirlist;
                if(!file_exists($dirpath))
                {
                    @mkdir($dirpath);
                    @chmod($dirpath,0777);
                }
            }
        }
    }
 
    /**
     * 垂直翻转
     *
     * @param    string     $src    图片源
     */
    function _flipV($src)
    {
        $src_x = $this->getImgWidth($src);
        $src_y = $this->getImgHeight($src);
 
        $new_im = imagecreatetruecolor($src_x, $src_y);
        for ($y = 0; $y < $src_y; $y++)
        {
            imagecopy($new_im, $src, 0, $src_y - $y - 1, 0, $y, $src_x, 1);
        }
        $this->h_src = $new_im;
    }
 
    /**
     * 水平翻转
     *
     * @param    string     $src    图片源
     */
    function _flipH($src)
    {
        $src_x = $this->getImgWidth($src);
        $src_y = $this->getImgHeight($src);
 
        $new_im = imagecreatetruecolor($src_x, $src_y);
        for ($x = 0; $x < $src_x; $x++)
        {
            imagecopy($new_im, $src, $src_x - $x - 1, 0, $x, 0, 1, $src_y);
        }
        $this->h_src = $new_im;
    }
}
?>

阅读全文

php给图片加水印四

<?

 /**
     * 生成水印,调用了生成水印文字和水印图片两个方法
     */
    function _createMask()
    {
        if($this->mask_word)
        {
            // 获取字体信息
            $this->_setFontInfo();
 
            if($this->_isFull())
            {
                die("水印文字过大");
            }
            else
            {
                $this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
                $white = ImageColorAllocate($this->h_dst,255,255,255);
                imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// 填充背景色
                $this->_drawBorder();
                imagecopyresampled( $this->h_dst, $this->h_src,
                                    $this->start_x, $this->start_y,
                                    $this->src_x, $this->src_y,
                                    $this->fill_w, $this->fill_h,
                                    $this->copy_w, $this->copy_h);
                $this->_createMaskWord($this->h_dst);
            }
        }
 
        if($this->mask_img)
        {
            $this->_loadMaskImg();//加载时,取得宽高
 
            if($this->_isFull())
            {
                // 将水印生成在原图上再拷
                $this->_createMaskImg($this->h_src);
                $this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
                $white = ImageColorAllocate($this->h_dst,255,255,255);
                imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// 填充背景色
                $this->_drawBorder();
                imagecopyresampled( $this->h_dst, $this->h_src,
                                    $this->start_x, $this->start_y,
                                    $this->src_x, $this->src_y,
                                    $this->fill_w, $this->fill_h,
                                    $this->copy_w, $this->copy_h);
            }
            else
            {
                // 创建新图并拷贝
                $this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
                $white = ImageColorAllocate($this->h_dst,255,255,255);
                imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// 填充背景色
                $this->_drawBorder();
                imagecopyresampled( $this->h_dst, $this->h_src,
                                    $this->start_x, $this->start_y,
                                    $this->src_x, $this->src_y,
                                    $this->fill_w, $this->fill_h,
                                    $this->copy_w, $this->copy_h);
                $this->_createMaskImg($this->h_dst);
            }
        }
 
        if(empty($this->mask_word) && empty($this->mask_img))
        {
            $this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
            $white = ImageColorAllocate($this->h_dst,255,255,255);
            imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// 填充背景色
            $this->_drawBorder();
 
            imagecopyresampled( $this->h_dst, $this->h_src,
                        $this->start_x, $this->start_y,
                        $this->src_x, $this->src_y,
                        $this->fill_w, $this->fill_h,
                        $this->copy_w, $this->copy_h);
        }
    }
 
    /**
     * 画边框
     */
    function _drawBorder()
    {
        if(!empty($this->img_border_size))
        {
            $c = $this->_parseColor($this->img_border_color);
            $color = ImageColorAllocate($this->h_src,$c[0], $c[1], $c[2]);
            imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$color);// 填充背景色
        }
    }
 
    /**
     * 生成水印文字
     */
    function _createMaskWord($src)
    {
        $this->_countMaskPos();
        $this->_checkMaskValid();
 
        $c = $this->_parseColor($this->mask_font_color);
        $color = imagecolorallocatealpha($src, $c[0], $c[1], $c[2], $this->mask_txt_pct);
 
        if(is_numeric($this->font))
        {
            imagestring($src,
                        $this->font,
                        $this->mask_pos_x, $this->mask_pos_y,
                        $this->mask_word,
                        $color);
        }
        else
        {
            imagettftext($src,
                        $this->font_size, 0,
                        $this->mask_pos_x, $this->mask_pos_y,
                        $color,
                        $this->font,
                        $this->mask_word);
        }
    }
 
    /**
     * 生成水印图
     */
    function _createMaskImg($src)
    {
        $this->_countMaskPos();
        $this->_checkMaskValid();
        imagecopymerge($src,
                        $this->h_mask,
                        $this->mask_pos_x ,$this->mask_pos_y,
                        0, 0,
                        $this->mask_w, $this->mask_h,
                        $this->mask_img_pct);
 
        imagedestroy($this->h_mask);
    }
 
    /**
     * 加载水印图
     */
    function _loadMaskImg()
    {
        $mask_type = $this->_getImgType($this->mask_img);
        $this->_checkValid($mask_type);
 
        // file_get_contents函数要求php版本>4.3.0
        $src = '';
        if(function_exists("file_get_contents"))
        {
            $src = file_get_contents($this->mask_img);
        }
        else
        {
            $handle = fopen ($this->mask_img, "r");
            while (!feof ($handle))
            {
                $src .= fgets($fd, 4096);
            }
            fclose ($handle);
        }
        if(empty($this->mask_img))
        {
            die("水印图片为空");
        }
        $this->h_mask = ImageCreateFromString($src);
        $this->mask_w = $this->getImgWidth($this->h_mask);
        $this->mask_h = $this->getImgHeight($this->h_mask);
    }
 
    /**
     * 图片输出
     */
    function _output()
    {
        $img_type  = $this->img_type;
        $func_name = $this->all_type[$img_type]['output'];
        if(function_exists($func_name))
        {
            // 判断浏览器,若是IE就不发送头
            if(isset($_SERVER['HTTP_USER_AGENT']))
            {
                $ua = strtoupper($_SERVER['HTTP_USER_AGENT']);
                if(!preg_match('/^.*MSIE.*)$/i',$ua))
                {
                    header("Content-type:$img_type");
                }
            }
            $func_name($this->h_dst, $this->dst_img, $this->img_display_quality);
        }
        else
        {
            Return false;
        }
    }
 
    /**
     * 分析颜色
     *
     * @param    string     $color    十六进制颜色
     */
    function _parseColor($color)
    {
        $arr = array();
        for($ii=1; $ii<strlen ($color); $ii++)
        {
            $arr[] = hexdec(substr($color,$ii,2));
            $ii++;
        }
 
        Return $arr;
    }
 
    /**
     * 计算出位置坐标
     */
   ?>

阅读全文

php 给图片加水印三

<?

function setMaskTxtPct($n)
    {
        $this->mask_txt_pct = (int)$n;
    }
 
    /**
     * 设置缩略图边框
     *
     * @param    (类型)     (参数名)    (描述)
     */
    function setDstImgBorder($size=1, $color="#000000")
    {
        $this->img_border_size  = (int)$size;
        $this->img_border_color = $color;
    }
 
    /**
     * 水平翻转
     */
    function flipH()
    {
        $this->_flip_x++;
    }
 
    /**
     * 垂直翻转
     */
    function flipV()
    {
        $this->_flip_y++;
    }
 
    /**
     * 设置剪切类型
     *
     * @param    (类型)     (参数名)    (描述)
     */
    function setCutType($type)
    {
        $this->cut_type = (int)$type;
    }
 
    /**
     * 设置图片剪切
     *
     * @param    integer     $width    矩形剪切
     */
    function setRectangleCut($width, $height)
    {
        $this->fill_w = (int)$width;
        $this->fill_h = (int)$height;
    }
 
    /**
     * 设置源图剪切起始坐标点
     *
     * @param    (类型)     (参数名)    (描述)
     */
    function setSrcCutPosition($x, $y)
    {
        $this->src_x  = (int)$x;
        $this->src_y  = (int)$y;
    }
 
    /**
     * 创建图片,主函数
     * @param    integer    $a     当缺少第二个参数时,此参数将用作百分比,
     *                             否则作为宽度值
     * @param    integer    $b     图片缩放后的高度
     */
    function createImg($a, $b=null)
    {
        $num = func_num_args();
        if(1 == $num)
        {
            $r = (int)$a;
            if($r < 1)
            {
                die("图片缩放比例不得小于1");
            }
            $this->img_scale = $r;
            $this->_setNewImgSize($r);
        }
 
        if(2 == $num)
        {
            $w = (int)$a;
            $h = (int)$b;
            if(0 == $w)
            {
                die("目标宽度不能为0");
            }
            if(0 == $h)
            {
                die("目标高度不能为0");
            }
            $this->_setNewImgSize($w, $h);
        }
 
        if($this->_flip_x%2!=0)
        {
            $this->_flipH($this->h_src);
        }
 
        if($this->_flip_y%2!=0)
        {
            $this->_flipV($this->h_src);
        }
        $this->_createMask();
        $this->_output();
 
        // 释放
        if(imagedestroy($this->h_src) && imagedestroy($this->h_dst))
        {
            Return true;
        }
        else
        {
            Return false;
        }
    }
 
   ?>

阅读全文

php自己写了一个模板

/*
作者: 牛哄哄
Q Q: 455703030
*/
function template($template,$cacheFile,$set)
{
is_readable($template) || exit('模板文件不存在!');
filemtime($template) > @filemtime($cacheFile) && parse_template($template,$cacheFile);
$inTemplate = true;
is_readable($cacheFile) ? include $cacheFile : exit('无法读取缓存,缓存路径可能有误!');
}
function parse_template($template,$cacheFile='')
{
$content = file_get_contents($template);
$content = preg_replace('/{*([^{}]*)*}/','',$content);
$content = preg_replace('/$([A-Za-z0-9_]+)/','$set['\1']',$content);
$content = preg_replace('/$[([A-Za-z0-9_]+)]/','$\1',$content);
$content = preg_replace('/{$([A-Za-z0-9_[]'"]+)}/','<? echo $\1; ?>',$content);
$content = preg_replace('/{include(([^{}]+))}/','<? include \1; ?>',$content);
$content = preg_replace('/{echofile(([^{}]+))}/','<? echo file_get_contents(\1); ?>',$content);
$content = preg_replace('/{code(([^{}]+))}/','<? \1; ?>',$content);
$content = preg_replace('/{if(([^{}]+))}/','<? if (\1) { ?>',$content);
$content = preg_replace('/{elseif(([^{}]+))}/','<? } elseif(\1) { ?>',$content);
$content = preg_replace('/{while(([^{}]+))}/','<? while (\1) { ?>',$content);
$content = preg_replace('/{foreach(([^{}]+))}/','<? foreach (\1) { ?>',$content);
$content = str_replace(array('{else}','{/if}','{/while}','{/foreach}'),array('<? }else{ ?>','<? } ?>','<? } ?>','<? } ?>'),$content);
if (preg_match_all('/{template(([^{}]+))}/',$content,$tplName))
{
  foreach ($tplName[1] as $value) $tplContent[] = parse_template(eval('return '.$value.';'));
  $content = str_replace($tplName[0],$tplContent,$content);
}
if ('' == $cacheFile) return $content;
@file_put_contents($cacheFile,'<? true===$inTemplate || exit('非法访问!'); ?>'.$content);
}

阅读全文

php+ajax无刷新实现省、地、市三级联动

<html>
<
head
>
<
meta http-equiv="Content-Type" 
/>
<
script type="text/javascript"
>
var 
xmlHttp
;
var 
requestType=""
;
function 
createXMLHttpRequest
()
{
if(
window.ActiveXObject
)
{
  
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"
);
}
else if(
window.XMLHttpRequest
)
{
  
xmlHttp=new XMLHttpRequest
();
}
}
function 
queryCity(citycode
){
createXMLHttpRequest
();
type="city"
;
var 
url="data.php?provincecode="+citycode
;
xmlHttp.open("GET",url,true
);
xmlHttp.onreadystatechange=handleStateChange
;
xmlHttp.send(null
);
}
function 
queryArea(citycode
){
createXMLHttpRequest
();
type="area"
;
var 
url="data.php?citycode="+citycode
;
xmlHttp.open("GET",url,true
);
xmlHttp.onreadystatechange=handleStateChange
;
xmlHttp.send(null
);
}
function 
handleStateChange
(){
if(
xmlHttp.readystate==4
){
  if(
xmlHttp.status==200
){
   if(
type=="city"
){
    
showcity
();
   }else if(
type="area"
){
    
showarea
();
   }
  }
}
}
function 
showcity
(){
document.getElementById("city").innerHTML=xmlHttp.responseText
;
document.getElementById("area").innerHTML=""
;
}
function 
showarea
(){
document.getElementById("area").innerHTML=xmlHttp.responseText
;
}
</script>
</head>
<body>
<?
$conn
=mysql_connect("localhost","root","2328725"
);
mysql_select_db("novel"
);
mysql_query("set names 'utf8'"
);
$sql="select * from province"
;
$result=mysql_query($sql
);
echo 
"<from id='form1'>n"
;
echo 
"<select id='province' onchange='queryCity(this.options[this.selectedIndex].value)'>n"
;
echo 
"<option value='-1' selected>请选择省份</option>n"
;
while(
$row=mysql_fetch_row($result
)){
  echo 
"<option value='$row[1]'>$row[2]</option>n"
;
}
echo 
"</select>n"
;
echo 
"<span id='city'></span>n"
;
echo 
"<span id='area'></span>n"
;
echo 
"</form>n"
;
?>

</body>
</html>

阅读全文

php把ubb代码转换成html

php把ubb代码转换成html

function  ubb($Text) 
  {
  $Text=htmlspecialchars($Text);
  $Text=stripslashes($Text); 
  $Text=ereg_replace("rn","<br/>",$Text);
  $Text=ereg_replace("r","<br/>",$Text);
  $Text=nl2br($Text);
  $Text=preg_replace("/\t/is"," ",$Text);
  $Text=ereg_replace("  ","&nbsp;",$Text); 
  $Text=preg_replace("/[h1](.+?)[/h1]/is","<h1>\1</h1>",$Text);
  $Text=preg_replace("/[h2](.+?)[/h2]/is","<h2>\1</h2>",$Text);
  $Text=preg_replace("/[h3](.+?)[/h3]/is","<h3>\1</h3>",$Text);
  $Text=preg_replace("/[h4](.+?)[/h4]/is","<h4>\1</h4>",$Text);
  $Text=preg_replace("/[h5](.+?)[/h5]/is","<h5>\1</h5>",$Text);
  $Text=preg_replace("/[h6](.+?)[/h6]/is","<h6>\1</h6>",$Text);
  $Text=preg_replace("/[center](.+?)[/center]/is","<center>\1</center>",$Text);
  $Text=preg_replace("/[big](.+?)[/big]/is","<big>\1</big>",$Text);
  $Text=preg_replace("/[small](.+?)[/small]/is","<small>\1</small>",$Text); 
  $Text=preg_replace("/[url](http://.+?)[/url]/is","<a  href=\1>\1</a>",$Text);
  $Text=preg_replace("/[url](.+?)[/url]/is","<a  href='http://\1'>http://\1</a>",$Text);
  $Text=preg_replace("/[url=(http://.+?)](.*)[/url]/is","<a  href=\1>\2</a>",$Text);
  $Text=preg_replace("/[url=(.+?)](.*)[/url]/is","<a  href=http://\1>\2</a>",$Text);
  $Text=preg_replace("/[img](.+?)[/img]/is","<img  src=\1  border=0>",$Text);
  $Text=preg_replace("/[color=(.+?)](.+?)[/color]/is","<font  color=\1>\2</font>",$Text);
  $Text=preg_replace("/[size=(.+?)](.+?)[/size]/is","<font  size=\1>\2</font>",$Text);
  $Text=preg_replace("/[sup](.+?)[/sup]/is","<sup>\1</sup>",$Text);
  $Text=preg_replace("/[sub](.+?)[/sub]/is","<sub>\1</sub>",$Text);
  $Text=preg_replace("/[pre](.+?)[/pre]/is","<pre>\1</pre>",$Text);
  $Text=preg_replace("/[email](.+?)[/email]/is","<a  href=mailto:\1>\1</a>",$Text);
  $Text=preg_replace("/[i](.+?)[/i]/is","<i>\1</i>",$Text);
  $Text=preg_replace("/[b](.+?)[/b]/is","<b>\1</b>",$Text);
  $Text=preg_replace("/[quote](.+?)[/quote]/is","<blockquote><font  size='1'  face='Courier  New'>quote:</font><hr>\1<hr></blockquote>",  $Text);
  $pattern = "/([uploadimage])(d+),(.*)([/uploadimage])/U";
  $replacement = "<img src="$3" >";
  $Text =@preg_replace($pattern, $replacement, $Text);
  $str  = $Text;
  $pattern='#[flash=(d+),(d+)](.+)[/flash]#';
  $last = "<center><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="$2" height="291">
  <param name="movie" value="$3" /><param name="quality" value="high" /><embed src="$3" quality="high"  pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"
  width="$2" height="$1"></embed></object><br>
  <a href="$3" >[全屏欣赏 提醒:Flash中可能包含不安全内容]</a>
  </center>";
  $Text= preg_replace($pattern, $last, $str); 
  $mpg ="<center>   
  <object align="middle" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" class="object" id="mediaplayer" width="$2" height="290">
  <param name="showstatusbar" value="-1" />
  <param name="filename" value="$3" />
  <embed type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701" filename="hong" src="$3" width="$2" height="$1">
  </embed>
  </object>
  </center>";
  $Text =preg_replace('#[mp=(d+),(d+)](.+)[/mp]#', $mpg, $Text);     
  return @iconv('utf-8','gbk',@iconv('gbk','utf-8',$Text));
     
  }

阅读全文

PHP的FTP学习(一)

的忠实FANS,我们因各种不同的原因使用它-WEB站点的开发,画图,数据库的联接等 -我们发现,它非常的友好,强大而且易于使用……  
你可能已经看到

阅读全文

优化PHP程序

网上很多文章介绍优化php程序,是通过安装ZendOptimizer之类的加速软件实现的,但这种加速是有限的。本文主要从程序代码着手介绍一些优化手段。

阅读全文