2015-10-19 43 views
0

我有一个问题,把文字放入图像。php每个字母图像

我的文件夹名为tekst

比方说我用$userinfo->name获取用户名,在这种情况下,用户名为zippo

然后,我希望用户名返回以下HTML输出:

<img src="tekst/z.png"><img src="tekst/i.png"><img src="tekst/p.png"><img src="tekst/p.png"><img src="tekst/o.png"> 

我该怎么办它用PHP将名称中的每个字母更改为<img src="tekst/?.png>。在结果数组如下

<?php 
$name = "zippo"; 
    for ($i = 0; $i < strlen($name); $i++) { 
    echo '<img src="tekst/' . $name[$i] . '.png">'; 
    } 
?> 

回答

2

您可以使用此

$letters = str_split($string); 
foreach ($letters as $letter) { 
    echo '<img src="tekst/' . $letter . '.png" />'; 
} 
0

首先,你必须创建一个PHP文件到您的文本转换为图像:

<?php 
/* image.php */ 

// Receive data 
$char = $_GET['char']; 
if(!empty($char)){ 
    // This will get the first character from $char 
    $char = $char; 
    // Create a 100*30 image 
    $im = imagecreate(100, 30); 

    // White background and blue text 
    $bg = imagecolorallocate($im, 255, 255, 255); 
    $textcolor = imagecolorallocate($im, 0, 0, 255); 

    // Write the string at the top left 
    imagestring($im, 5, 0, 0, $char, $textcolor); 

    // Output the image 
    header('Content-type: image/png'); 

    imagepng($im); 
    imagedestroy($im); 
} 
?> 

图像串http://php.net/manual/en/function.imagestring.php

再拆其名称字符

<?php 
$string = 'abcdefgh'; // For example 
$chars = str_split($string); 
foreach ($chars as $char) { 
    echo '<img src="tekst/image.php?char='.$char.'"/>'; 
} 
?> 

str_splithttp://php.net/manual/en/function.str-split.php

GOOD LUCK

1

试试这个

$letters = str_split($string); 
foreach ($letters as $letter) { 
    echo '<img src=".../tekst/' . $letter . '.png" />'; 
} 
相关问题