Php 字符串的垂直方向插入mysql

Php 字符串的垂直方向插入mysql,php,Php,我想更改保存到db中的字符串字母的方向。 e、 g我想让HELLO这个词看起来像这样: H W E O L R L L O D 我试过了,但给我看问号 echo "<table>"; $res=$functions->query("SELECT string1 FROM table"); while ($row = mysql_fetch_assoc($res)){ $hor=str_split($row['string1'

我想更改保存到db中的字符串字母的方向。 e、 g我想让HELLO这个词看起来像这样:

    H W
    E O
    L R
    L L
    O D
我试过了,但给我看问号

echo "<table>";

$res=$functions->query("SELECT string1 FROM table");

while ($row = mysql_fetch_assoc($res)){
    $hor=str_split($row['string1']);
    foreach ($hor as $letter) {
         $vert=$letter."\n";        
    }
    echo"<th>".$vert."</th>";   
}

// other functions... 

echo "</table>";

您应该使用以下代码更改foreach语句:

foreach($hor as $letter) {
    $vert .= $letter . "\n";
}

您忘记了显示所有字母所必需的问题。

您需要附加到$vert,否则您会不断覆盖,只会得到最后一个值

foreach ($hor as $letter) {
  $vert=$vert.$letter."\n";        
}

塔达!试试这个,代码中的注释中有解释:

$str = "HELLO HOW YA DOING WORLD?";

// Convert $str to an array of rows of letters.
$strWords          = explode(' ', $str);
$strLettersRowsArr = array_map('mb_split', $strWords);

// Get maximium number of rows of letters e.g. `strlen("WORLD?")` => `6`.
$maxRows = 0;
foreach ($strLettersRowsArr as $lettersArr) {
    if (count($lettersArr) > $maxRows) {
        $maxRows = count($lettersArr);
    }
}

// Pad out the elements of $strLettersRowsArr with spaces that aren't as long as the longest word.
// e.g.
// from:
// [
//     ['H', 'e', 'l', 'l', 'o'],
//     ['d', 'u', 'd', 'e'],
// ]
// to:
// [
//     ['H', 'e', 'l', 'l', 'o'],
//     ['d', 'u', 'd', 'e', ' '],
// ]
foreach ($strLettersRowsArr as $key => &$lettersArr) {
    while (count($lettersArr) < $maxRows) {
        $lettersArr[] = ' ';
    }
}
unset($lettersArr);

// Get the columns of letters.
// e.g.
// from:
// [
//     ['H', 'e', 'l', 'l', 'o'],
//     ['w', 'o', 'r', 'l', 'd'],
// ]
// to:
// [
//     ['H', 'w'],
//     ['e', 'o'],
//     ['l', 'r'],
//     ['l', 'l'],
//     ['o', 'd'],
// ]
$strLettersColumnsArr = [];
for ($row = 0; $row < $maxRows; $row++) {
    $strLettersColumnsArr[] = array_column($strLettersRowsArr, $row);
}

// Print out letter columns.
foreach ($strLettersColumnsArr as $lettersColumnArr) {
    foreach ($lettersColumnArr as $letter) {
        echo "$letter ";
    }
    echo "\n";
}

你的答案是正确的,但只有拉丁字母。我想显示希腊字符,但输出是?你应该说在你的问题中,我对希腊字母有问题,而不是用HELLOI。首先,你应该在你的问题中包含这个要求。第二,解决方法是使用
H H Y D W 
E O A O O 
L W   I R 
L     N L 
O     G D 
        ?