php 使用echo就报错....

刚开始学php,写了一段文字生成图片的代码。现在发现不能将text传至php里,而且就算不传参。直接在php里定义$ment = $_POST['text'_] 也会报错:图像xxx因存在错误无法显示,肯定不是字体的问题,我快疯了..谁能帮帮我...代码如下
index.html:

 <html>
    <head>
        <title>Logo Generater</title>
    </head>
    <body>
        <form method="post" action="logo generate.php">
        <label for="text">Company name:</label>
        <input type="text" name="text" id="text"/>
        <input type="submit" name="submit" id="submit" value='OK'>
        </form>
    </body>
</html>

logo generate.php:

<?php
$ment = 'What are you 弄啥类?'
$ment = $_POST['text'];
echo $ment;
echo strlen($ment);
$im = imagecreate(450,50);
$white = imagecolorallocate($im,0,0,0);
#imagecolortransparent($im,$white); 
$black = imagecolorallocate($im,255, 255,255);
imagettftext($im,26,0,15,40,$black,'E:\xampp\htdocs\test\simsun.ttc',$ment);
header("Content-type:image/png");
imagepng($im);
?>

谢谢了...
-------------------------16:35更新-----------------------
谢谢帮助我的人~(づ ̄ 3 ̄)づ
还有个问题 能不能像这张图一样,点击OK,传参给PHP,之后还在这个界面显示图片图片说明
以下是新代码~

 <html>
    <head>
        <title>Logo Generater</title>
    </head>
    <body>
        <form  action="logo generate.php" method="post">
        <h1>Logo Generater</h1>
        <h2>wirte by Yates WANG</h2>
        <label for="ment">Company name:</label>
        <input type="text" name="ment" id="ment"/>
        <input type="submit" name="submit" id="submit" value='OK'>
        <br/>
        <br/>
        <img src="logo generate.php" />
        <form>
    </body>
</html>
 <?php
#$ment = 'What are you 弄啥类?';
$ment = $_POST['ment'];
#echo strlen($ment);
#$len = strlen($ment) * 30;
$im = imagecreate(400,50);
$white = imagecolorallocate($im,0,0,0);
#imagecolortransparent($im,$white); 
$black = imagecolorallocate($im,255, 255,255);
imagettftext($im,26,0,15,40,$black,'C:\Windows\Fonts\simsun.ttc',$ment);
header("Content-type:image/png");
imagepng($im);
imagedestroy($im);
?>

再次感谢!

查看全部
YatesWANG
Yates WANG
2015/08/06 07:24
  • php
  • 点赞
  • 收藏
  • 回答
    私信

2个回复