我想从用户那里获得画布的大小。。当用户给定特定的像素大小时,画布将按该大小绘制。。我正在尝试运行此代码,但它不起作用。。我试图通过表单获得它,并在PHP中定义了值。。这两种方式都不起作用。。
<html>
<body style=" background: lightblue;">
<?php
//@$height=['$height'];
//@$width=['$width'];
$h=420;
$w=420;
?>
<center>
<form name="test" action="Untitled-1.php">
Please enter height : <input type="text" name="height"> <br>
Please enter widht : <input type="text" name="width"> <br>
<input type="submit" value="submit" name="submit"> <br>
</form>
</center>
<!-- <canvas id="canvas" width="420px" height="420px" style="background: #fff; magrin:20px;"> -->
<canvas id="canvas" height=<?php '".$h."' ?> width=<?php '".$w." '?> Style="background: #fff;">
<!-- <canvas id="canvas" height=<?php '".$height."' ?> width=<?php '".$width." '?> Style="background: #fff;"> -->
Browser does not support canvas
</canvas>
</body>
</html>
您没有用PHP打印输出。
更换
<canvas id="canvas" height=<?php '".$h."' ?> width=<?php '".$w." '?> Style="background: #fff;">
带
<canvas id="canvas" height="<?= $h; ?>" width="<?= $w; ?>" Style="background: #fff;">
如果也不起作用,则没有启用short_open_tag
,因此请将<?=
替换为<?php echo
。
您可以使用以下表达式:
<?php echo '<canvas id="canvas" height='.$h.' width='.$w' Style="background: #fff">'; ?>