无法修改标题信息 - 标题已发送

问题描述:

<?php 

require_once 'wordwrap.php'; 
$text="Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum"; 
$im=imagecreatefrompng('testing.png'); 
$arr=word($text); 
$white = imagecolorallocate($im,255,255,255); 
$grey = imagecolorallocate($im, 128, 128, 128); 
$font='arial.ttf'; 
$m=121; 
for($i=0;$i<sizeof($arr);$i++) 
{ 

    //imagettftext($im,12,0,11,$m+$t,$grey,$font,$arr[$i]); 
//echo $arr[$i]."<br/>"; 

} 
header('Content-type: image/png'); 
imagepng($im); 
imagedestroy($im); 
?> 

我得到错误。无法修改标题信息 - 标题已发送

Warning: Cannot modify header information - headers already sent by (output started at /home2/puneetbh/public_html/prideapp/Testing/wordwrap.php:33) in /home2/puneetbh/public_html/prideapp/Testing/checkimage.php on line 16 
‰PNG ��� IHDR�� ��ô���J"Þ/�� �IDATxœì¼KvÉŽ%ŠŸ}Ü)EfäjÕxÝËÇ›nE^)Èãn?�Õ€J‘UÕ~ß --ŠKä>ƒÛàÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ7nܸqãÆ 
+0

哪条线上面说的错误是吗? – 2010-05-05 12:12:39

+0

请学会复制整个错误信息,而不是它的一部分。你也可以阅读它 - 这是非常清楚的 – 2010-05-05 12:12:53

您的wordwrap.php文件不应该输出一个字节。但它在第33行中列印了一些东西。你可以检查这一行,看看发生了什么。

也考虑使用内置PHP函数wordwrap()而不是包含一些奇怪的代码。

因此,使它像这样:

<?php 

#require_once 'wordwrap.php'; 
$text="Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum"; 
$im=imagecreatefrompng('testing.png'); 
$arr=explode("\n",wordwrap($text,24,"\n")); 
$white = imagecolorallocate($im,255,255,255); 
$grey = imagecolorallocate($im, 128, 128, 128); 
$font='arial.ttf'; 
$m=121; 
for($i=0;$i<sizeof($arr);$i++) 
{ 

    //imagettftext($im,12,0,11,$m+$t,$grey,$font,$arr[$i]); 
//echo $arr[$i]."<br/>"; 

} 
header('Content-type: image/png'); 
imagepng($im); 
imagedestroy($im); 
?> 
+0

24) \t { \t \t $海峡= SUBSTR($件[$ i]于,0,24); $ str =“。”substr($ pieces [$ i],24,strlen(str)); \t \t \t } \t \t 其他 \t { \t \t如果(strlen的($件[$ i]于)> $ spaceleft) \t \t \t { \t \t \t $ spaceleft = 24; \t \t \t $ text = $ text。“:”。$件[$ i]于; \t \t \t} \t \t别的 \t \t { \t \t \t $ spaceleft = $ spaceleft-(strlen的($件[$ i]于)+ 1); \t \t \t $ text = $ text。$ pieces [$ i]。“”; \t \t} \t} \t } $ p = explode(“:”,$ text); return $ p; } ?> – goblin2986 2010-05-05 13:38:18

+0

这是我的wordwrap功能。 – goblin2986 2010-05-05 13:39:05

+0

@bhaskaragr我在这里看不到第33行。但是根本不要使用它。使用我添加的代码 – 2010-05-05 13:43:03

输出缓冲反过来改变头 - >http://php.net/manual/en/function.ob-start.php

写给你的代码的顶部。

 
ob_start(); 
+1

这是大规模的过度杀死只能解决问题。相反,修复问题会更好。 – meagar 2010-05-05 12:21:53

+0

Upvoted,输出缓冲对于某些问题来说是一种很好的技术,突出它存在是非常合理的,特别是如果开发人员之前没有遇到过。 – dmp 2010-05-05 13:36:34

+0

经过我的系统奇怪的行为,我找不到任何空白空间,没有什么,也绝不是重定向,然后我的解决方法是这样的 - >回声'';真的行!是不是最好的解决方案,但经过很多麻烦因为一个简单的重定向不起作用,我想出了这个.. – B4NZ41 2011-10-26 16:09:40

确保在<?php之前没有空格或返回。 此外,如果您的文件编码为UTF-8,请确保它没有BOM

+0

不,我运行在ANSI编码。 – goblin2986 2010-05-05 12:47:40