php - 检查每个字母并为每个字母写文本

标签 php html arrays

我想以与该图片链接中显示的方式相同的方式获取结果。我尝试了很多次来获得该解决方案,但无法找到解决此问题的任何方法。图片链接(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); 
?>

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

最佳答案

要按字母拆分单词,您可以使用

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 - 检查每个字母并为每个字母写文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29649374/

相关文章:

php - 如果未修改,使 PHP 页面返回 "304 Not Modified"

php - 多个查询 MySQL 与 PHP

php - 运行查询时为 "USE statement is not supported to switch between databases"

html - 960 网格 CSS : How do I change vertical padding between divs?

javascript - 在对象方法调用上使用两组括号的原因是什么

javascript - 使用 addClass() 切换 Canvas 外菜单

java - 数组 : if (data[a]. 的增强循环包含 ("word")) 问题:类型不兼容

PHP 替代 mysql_data_seek for ODBC

arrays - 为动态填充的对象数组生成 Mongoose 模式

javascript - 从javascript中的数组中查找中值(8个值或9个值)