首页 > phper

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程序

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

阅读全文

PHP通用文件上传类

由于做项目中经常遇到文件上传,因此封装了一个通用的文件上传类,作用支持组文件上传,并且不同的上传域可以上传不同的文件类型,不同的文件类型限制的文件大小也可能不相同。举例来说:用户可上传一种展品并可为该展品上传一张缩略图,那么缩略图文件限制类型可能为jpg,gif,png等,而展品文件限制类型可能为mov,avi,mpeg等,而图片大小可能限制为100KB,音频视频大小可能限制为2MB。类代码如下: 

阅读全文

PHP你所不知道的10件事

小编之前也曾报导过PHP开发人员容易忽略的几点精华,除了一些精华技术方法外,很多细微之处也是程序员们容易忽略的,下面我们为您总结了10个关于PHP你可能不知道的事情。

阅读全文