谈谈国内三大PHP播客系统代码试用体验和建议 最近准备弄个播客玩玩,便找了一个PHP的开源博客系统,本人先申明下对网站开发不了解,说的也许就是个人自见。不足之处请指正。请勿见笑,欢迎交流,QQ:147468.
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" c />
<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 框架,第 1 部分: 开始使用三种常用框架
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(" "," ",$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学习(二)
服务器,
提供了一些函数,它们能获取一些关于系统和文件以及目录的信息。
PHP的FTP学习(一)
的忠实FANS,我们因各种不同的原因使用它-WEB站点的开发,画图,数据库的联接等 -我们发现,它非常的友好,强大而且易于使用……
你可能已经看到
优化PHP程序
网上很多文章介绍优化php程序,是通过安装ZendOptimizer之类的加速软件实现的,但这种加速是有限的。本文主要从程序代码着手介绍一些优化手段。
PHP通用文件上传类
由于做项目中经常遇到文件上传,因此封装了一个通用的文件上传类,作用支持组文件上传,并且不同的上传域可以上传不同的文件类型,不同的文件类型限制的文件大小也可能不相同。举例来说:用户可上传一种展品并可为该展品上传一张缩略图,那么缩略图文件限制类型可能为jpg,gif,png等,而展品文件限制类型可能为mov,avi,mpeg等,而图片大小可能限制为100KB,音频视频大小可能限制为2MB。类代码如下:
php实现多线程(实际是多进程,跨平台)
代码实现了一个简单的多进程管理机制,比向WEB服务器发送多个请求要实现多进程要方便很多。只能使用在cli模式。可以用在特殊场合,如邮件发送任务等。