<?php
header('Content-Type:text/html;charset=gb2312');
$animation = new Imagick();
$animation->setFormat( "gif" );
$image = new Imagick('/skin/'.$_GET["ys"].'.gif');
$unitl = $image->getNumberImages();
for ($i=0; $i<$unitl; $i++) {
$image->setImageIndex($i);
$first = new Imagick($_GET["yh"]);
$bl = new Imagick("/skin/bl.jpg");
$thisimage = new Imagick();
$thisimage->readImageBlob($image);
$srcwh = $thisimage->getImageGeometry();
$bl->thumbnailImage ($srcwh["width"],$srcwh["height"],false);
if ($_GET["kuan"]==0 and $_GET["gao"]==0)
{
$first->thumbnailImage ($srcwh["width"],$srcwh["height"],false); //这里false就是拉伸了 true为不拉伸
}
else
{
$first->thumbnailImage ($_GET["kuan"],$_GET["gao"],false); //这里false就是拉伸了 true为不拉伸
}
$bl->compositeImage($first,Imagick::COMPOSITE_OVER,$_GET["x"],$_GET["y"]);
$delay = $thisimage->getImageDelay();
$bl->compositeImage($thisimage,Imagick::COMPOSITE_OVER,0,0);
$animation->addImage($bl);
$animation->setImageDelay( $delay );
}
$picname=date("ymdhs")."_".mt_rand(10000,99999).".gif";
$name = "/user/".$picname;
$animation->writeImages($name,1);
echo "<H1></H1>
<DIV class=stborder>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD id=picMain align=middle> <img id="qqq" name="qqq"" width=100% src="/user/{$picname}"><br><iframe name=demo style="display:none"></iframe>
<a href=#pic onclick="savepic(document.getElementById('qqq'))"><font style="color: #FFFFFF; text-decoration: underline; font-size: 12px;">下载图片</font></a> <a href=#pic onclick="copypic(0,'qqq')"><font style="color: #FFFFFF; text-decoration: underline; font-size: 12px;">复制图片</font></a>
</TD></TR></TBODY></TABLE></DIV>
<DIV class=clear></DIV>";
//header( "Content-Type: image/gif" );
//echo $animation->getImagesBlob();
//echo $animation;
?>
warning: Cannot add header information - headers already sent in
output_buffering被启用时,在脚本发送输出时,PHP并不发送HTTP header。相反,它将此输出通过管道(pipe)输入到动态增加的缓存中(只能在PHP 4。0中使用,它具有中央化的输出机制)。你仍然可以修改/添加header,或者设置cookie,因为header实际上并没有发送。当全部脚本终止时,PHP将自动发送HTTP header到浏览器,然后再发送输出缓冲中的内容。
首先:这错误是怎么产生的呢?让我们来看看PHP是如何处理HTTP header输出和主体输出的。
PHP脚本开始执行时,它可以同时发送header(标题)信息和主体信息。 Header信息(来自 header() 或 SetCookie() 函数)并不会立即发送,相反,它被保存到一个列表中。 这样就可以允许你修改标题信息,包括缺省的标题(例如 Content-Type 标题)。但是,一旦脚本发送了任何非标题的输出(例如,使用 HTML 或 print() 调用),那么PHP就必须先发送完所有的Header,然后终止 HTTP header。而后继续发送主体数据。从这时开始,任何添加或修改Header信息的试图都是不允许的,并会发送上述的错误消息之一。
好!那我们来解决它:
笨方法:把错误警告全不显示!
掩耳盗铃之计,具体方法就不说了 ^_^#
解决方案:
1)适用于有权限编辑PHP。INI的人
打开php。ini文件(你应试比我清楚你的php。ini在哪里),找到
output_buffering =改为on或者任何数字。如果是IIS6,请一定改为ON,不然你的PHP效率会奇慢。
2)使用虚拟主机,不能编辑PHP。INI,怎么办?
简单:
在你的空间根目录下建立一个。htaccess文件,内容如下:
AllowOverride All
PHP_FLAG output_buffering On
不幸的情况是:还是不行?全部网页都不能显示啦?
那么,你可以打电话骂一通空间商,然后让他给你把apache的。htaccess AllowOverride打开
3)在PHP文件里解决
ob_start()
启用output buffering机制。 Output buffering支持多层次 -- 例如,可以多次调用 ob_start() 函数。
ob_end_flush()
发送output buffer(输出缓冲)并禁用output buffering机制。
ob_end_clean()
清除output buffer但不发送,并禁用output buffering。
ob_get_contents()
将当前的output buffer返回成一个字符串。允许你处理脚本发出的任何输出。
如果一个包含二元运算符的表达式出现在三元运算符\" ? : \"的\"?\"之前,那么应该给表达式添上一对圆括号。例如: (x >= 0) ? x : -x;
在php很多编程中都会看到?与:的组合用法,这种组合叫做三元运算符了,
运算符"?"前的表达式
如果一个包含二元运算符的表达式出现在三元运算符" ? : "的"?"之前,那么应该给表达式添上一对圆括号。例如:
(x >= 0) ? x : -x;
下面我们来看一个简单的?号表达式实例
<?
$a=1;
echo $a?'true':'false';
输出结果为 trur;
再看
if( $a )
{
echo 'true';
}
else
{
echo 'false';
}
用if输出的结果同样也为true哦,从这里可以看了?表达式可以处理一些简单的条件运算。
本站原创转载注明来自:www.111cn.net
本文章要讲的是关于php的substr函数与自己写了一个中英文截取函数哦,关于首先我们来看看substr这个函数的使用方法吧。substr实例
$content ='i love you www.111cn.net';
$temp = substr($content,4);
echo $temp;
结果:
love you www.111cn.net' //
下面来看看从右边取函数。
$temp = substr($temp,0,-4);
结果为:
i love www.111c
好了,下面我们再来看中文截函数吧。
function MooCutstr($string, $length, $dot = ' ...') {
global $charset;
if(strlen($string) <= $length) {
return $string;
}
$string = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string);
$strcut = '';
if(strtolower($charset) == 'utf-8') {
$n = $tn = $noc = 0;
while($n < strlen($string)) {
$t = ord($string[$n]);
if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
$tn = 1; $n++; $noc++;
} elseif (194 <= $t && $t <= 223) {
$tn = 2; $n += 2; $noc += 2;
} elseif (224 <= $t && $t < 239) {
$tn = 3; $n += 3; $noc += 2;
} elseif (240 <= $t && $t <= 247) {
$tn = 4; $n += 4; $noc += 2;
} elseif (248 <= $t && $t <= 251) {
$tn = 5; $n += 5; $noc += 2;
} elseif ($t == 252 || $t == 253) {
$tn = 6; $n += 6; $noc += 2;
} else {
$n++;
}
if($noc >= $length) {
break;
}
}
if($noc > $length) {
$n -= $tn;
}
$strcut = substr($string, 0, $n);
} else {
for($i = 0; $i < $length; $i++) {
$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
}
}
//$strcut = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $strcut);
return $strcut.$dot;
}
php substr它不能自动识别中英,所以很多朋友在用substr读取中文与英的字符串会有时会出现乱码了,使用第二种方法就OK了。
下面是一个简单的函数,我们是用php file_get_contents函数来读取文件mail_room.html的内容哦,好了费话不说多了我们来看看吧。
function GetContent($type){
if( $type )
{
if(file_exists('./mail_room.html') )
{
$content = file_get_contents( './mail_room.html');
}
else
{
ShowMsg('file can' read fail ');
}
}
else
{
if( file_exists( './mail_person.html') )
{
$content = file_get_contents( './mail_person.html');
}
else
{
ShowMsg('person file read fail!');
}
}
return $content;
}
本站原创转注明:www.111cn.net/phper/php.html