在变量中使用PHP输入的数据
所以我试图将变量“String”设置为输入的值,但我似乎无法理解。。。。代码如下:在变量中使用PHP输入的数据,php,html,input,handle,Php,Html,Input,Handle,所以我试图将变量“String”设置为输入的值,但我似乎无法理解。。。。代码如下: <input type="text" name="name" value="<?php echo $name;?>"> <?php $string = $_GET["name"]; $string2 = "example.com"; $image = imageCreateFromPng("http://i.imgur.com/2AKemxI.png"); $cor = imag
<input type="text" name="name" value="<?php echo $name;?>">
<?php
$string = $_GET["name"];
$string2 = "example.com";
$image = imageCreateFromPng("http://i.imgur.com/2AKemxI.png");
$cor = imagecolorallocate($image, 255, 255, 255);
$background = imagecolorallocate($image, 0, 0, 0);
imagecolortransparent($image, $background);
imagealphablending($image, false);
imagesavealpha($image, true);
imagestring($image,5,110,22,urldecode($string),$cor);
imagestring($image,5,110,53,urldecode($string2),$cor);
header('Content-type: image/png');
imagepng($image,NULL);
?>
首先,使用标题('Content-type:image/png')代码>在html标记(输入)之后,必须始终在调用任何html之前调用header函数。。。你应该把你的输入以适当的形式放到另一个页面,调用包含你的php的页面,就像其他人说的,你的问题有点吓人
也就是说,(这可能是用简单的术语来思考,如果是的话,请原谅)您是在发布还是在获取您的表单。原因如果您的表单如下所示:
<form action="url" method="post">
您应该使用您正在学习的$\u POST
,因此请尝试发送您从其他页面获取的信息。像这样的人:
form.html
<form method="get" action="imagecreate.php">
<input type="text" name="name" value="">
<input type="submit" />
</form>
imagecreate.php
<?php
$im = imageCreateFromPng("teste.png");
$cor = imagecolorallocate($im, 255, 255, 255);
$background = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent($im, $background);
imagealphablending($im, false);
// display string
imagestring($im, 5, 0, 0, $_GET['name'], $cor);
// print image
header("Content-type: image/png");
imagepng($im);
}
那么,什么不起作用,如果有错误,检查错误。。。?表单被正确地语法化。可以是很多事情中的一个。代码表明您正在尝试内联执行此操作,就像这是javascript一样。是这样的(这是您在这里列出的一个文件中的吗?)还是我们缺少了@Fred ii-要求您提供的其他代码?