【问题标题】:check each alphabet and write text for each alphabet检查每个字母并为每个字母写文本
【发布时间】:2015-06-21 08:43:35
【问题描述】:

我想以与该图片链接中显示的相同方式获取结果。我尝试了很多次以获得该解决方案,但无法找到任何解决此问题的方法。图片链接(http://haha123456.hol.es/death/abs2.jpg)

我的html代码是:

<html>
<body>
<form action="result.php" method="get">
<input type="text" name="name" id="name">
<input type="button" name="submit" id="submit">
</form>
</body>
</html>

我的php代码是:result.php

<?php
header('Content-type: image/jpeg');
$jpg_image = imagecreatefromjpeg('Desert.jpg');
$white = imagecolorallocate($jpg_image, 73, 41, 236);
$font_path = 'OpenSans-Italic.TTF';
$text = $_GET['name'] ;
imagettftext($jpg_image, 25, 0, 75, 50, $white, $font_path, $text);
imagejpeg($jpg_image);
imagedestroy($jpg_image); 
?>

而且我还为每个字母创建了一些数组,但只是没有得到正确的命令来拆分作为输入给出的单词并根据链接图片中给出的每个字母从数组中显示一些单词。

【问题讨论】:

  • 你能发布你的错误或什么不工作?

标签: php html arrays


【解决方案1】:

要逐字分割,你可以使用

str_split($str);

要通过第一个字母从某个数组中获取数据,首先,我建议使用

array("a" => "Acrobat","b" => "bull");

等等。

在这种情况下,代码将是:

$arr = array("a" => "Acrobat","b" => "bull");
$result = str_split($str);
foreach ($result as $letter) {
 echo $arr[$letter];
}

【讨论】:

  • 使用你的想法我创建了这个 php 编码
  • 使用你的想法我创建了这个 php 编码&lt;?php header('Content-type: image/jpeg'); $jpg_image = imagecreatefromjpeg('Desert.jpg'); $white = imagecolorallocate($jpg_image, 73, 41, 236); $font_path = 'OpenSans-Italic.TTF'; $text = $_GET['name'] ; $arr = array("a" =&gt; "Acrobat","b" =&gt; "bull"); $result = str_split($_GET['name']); foreach ($result as $letter){ imagettftext($jpg_image, 25, 0, 75, 50, $white, $font_path, $arr[$letter]);} imagejpeg($jpg_image); imagedestroy($jpg_image); ?&gt; 它正在工作,但字母出现在同一区域,所以它混淆了所以你能帮助我
  • 如果我要创建这样的功能 - 我会避免使用 css 创建图像和输出数据。
    Sometext
    div { 宽度:10px;字体大小:50px; word-wrap:断词;也有可能安装 [phantomjs.org/] 并生成图像。如果您真的需要图像 - 您可以在 imagettftext 函数中增加“Y”参数,例如: imagettftext($jpg_image, 25, 0, 75, 50, $white, $font_path, $arr[$letter]); imagettftext($jpg_image, 25, 0, 75, 100, $white, $font_path, $arr[$letter]); imagettftext($jpg_image, 25, 0, 75, 150, $white, $font_path, $arr[$letter]);
  • 如何在这个数组$arr = array("a" =&gt; "Acrobat","b" =&gt; "bull");中添加更多命名为“A”的内容,例如“可爱”,并随机选择它们
  • 将它们添加为数组,并使用随机获取一个
猜你喜欢
相关资源
最近更新 更多
热门标签