-3

这是我的代码。我想要实现的是得到这样的文本

Hola   Hi
Pollo   Chicken
Queso   Cheese

依此类推,并且能够从中制作一个数组,使得

数组[0][1] 是嗨。这是我的代码,错误在第 13 行

<?php

if(isset($_POST['submit'])){
$message = $_POST['text'];
$words2 = explode("\r\n", $message);
$words = explode("\t", $words2[0]);
$numberoflines = count($words2);
echo $numberoflines;
for($i=0; $i<$numberoflines; $i++){
$words[$i] = $line;
$arrayline = explode("\t", $line);
$cow = array( 
    for($u=0; $u<2; $u++){
        array($arrayline[$u])
            }
        );
}
}
?>
<html>
<form method = "POST" method ="changetext.php">
<textarea name="text">
</textarea>
<input type="submit" value = "Flip!" name="submit">
</form>

</html>
4

2 回答 2

0

尝试这样的事情:

$words = array();
if(isset($_POST['submit'])){
    // Break down the text as lines:
    $lines = explode("\r\n", $_POST['text']);

    // For every line...
    foreach($lines as $line){
        // Seperate the 2 words (seperated by a tab)
        $words[] = explode("\t", $line);
    }

    // Print the result:
    var_dump($words);
}
于 2013-02-10T19:10:59.303 回答
0

也许这就是你想要达到的目标?!?

for($i=0; $i<$numberoflines; $i++){
 $arraycols= explode("\t", $words[$i]);
 foreach($arraycols as $col){
    $list[$i][] = $col;
 }
} 

所以数组 $list 是 $list[row][col]

如果我猜对了 $words 数组中的内容。你的代码有点混乱;)

于 2013-02-10T18:45:16.750 回答