2010-05-05 92 views
0
<?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

回答

3

您的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

<?php function word($ string) { $ spaceleft = 24; $ pieces = explode(「」,$ string); 爲($ I = 0; $ I <的sizeof($件); $ I ++) { \t如果(strlen的($件[$ i]於)> 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

0

輸出緩衝反過來改變頭 - >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

2

確保在<?php之前沒有空格或返回。 此外,如果您的文件編碼爲UTF-8,請確保它沒有BOM

+0

不,我運行在ANSI編碼。 – goblin2986 2010-05-05 12:47:40

相關問題