[菲律宾语]将文本区域元素插入数组并打印出来


[PHP]Insert TextArea elements into array and print it

我对PHP相当陌生。我正在开发一个小工具,它从列表框中获取元素(列表框包含从文本文件加载的元素),然后将其与手动插入文本区域内的其他字符串合并。

更多解释 :有一个列表框,用于从文本文件
加载字符串然后我有一个文本区域,用户在其中输入文本(字符串)
按下按钮时,我希望应用程序将列表框中的每个项目与文本区域中的每个项目合并,例如:

[LISTBOX]
ITALY
USA
GERMANY
[TEXTAREA]
GREAT
GOOD
VERY GOOD
[PRINTED RESULT ON BUTTON PRESS]
ITALY GREAT
ITALY GOOD
ITALY VERY GOOD
USA GREAT
USA GOOD
USA VERY GOOD
GERMANY GREAT
GERMANY GOOD
GERMANY VERY GOOD

我的代码 http://sharetext.org/RaB3

<html>
<head><title>TOOL</title></head>
<body>
<div align="center">
<img src="../img/logo.png" width="30%" height="16%">
</div>
<br><br>
<table>
<tr>
<td>
<?php
$file_handle = fopen("myfile.txt", "rb");
$i=0;
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts = explode(';', $line_of_text);
$citta[$i]=array($parts[0]);
$i=$i+1;
}
fclose($file_handle);
?>
<div name="lista" align="left">
<select name="listacitta" multiple="multiple">')
<?for ($cit = 0; $cit <= $i-2; ++$cit)
{
        echo('<option>' . $citta[$cit][0] .'</option>');
    } ?>
</select>
</div></td>    
<td>
<textarea name="keywords" width="500" height="400" rows="10" cols="40"></textarea>
<?
for ($eco = 0; $eco <= $i-2; ++$eco)
{
//echo('ciao ' . $citta[$eco][0] . '<br>');
}
?>
</td>
</body>
</html>
我希望

我答对了问题,我认为这就是你需要的:

<html>
<head>
    <title>TOOL</title>
</head>
<body>
    <div align="center">
        <img src="../img/logo.png" width="30%" height="16%">
    </div>
    <br><br>
    <form action="#" method="post">
    <table> 
        <tr>
            <td> 
                <?php 
                $file_handle = fopen("myfile.txt", "rb"); 
                while (!feof($file_handle) ) { 
                    $line_of_text = fgets($file_handle); 
                    $parts = explode(';', $line_of_text); 
                } 
                fclose($file_handle); 
                ?> 
                <div name="lista" align="left"> 
                    <select name="listacitta[]" multiple="multiple">
                        <?php 
                        for($cit = 0; $cit<count($parts); $cit++) { 
                          echo('<option value="' . $parts[$cit] . '">' . $parts[$cit] .'</option>'); 
                        };
                        ?> 
                    </select> 
                </div>
            </td> 
            <td> 
            <textarea name="keywords" width="500" height="400" rows="10" cols="40"></textarea>
            </td>
        </tr>
    </table>
    <input name="submit" type="submit" value="Submit">
    </form>
<?php
    if(isset($_POST['submit']) && !empty($_POST['keywords']) && !empty($_POST['listacitta'])) {
        $usertext = $_POST['keywords'];
        $userSelect = $_POST['listacitta'];
        $userTparts = explode(';', $usertext);
        for($z=0;$z<count($userSelect);$z++) {
            for($y=0;$y<count($userTparts);$y++){
                echo $userSelect[$z] . " " . $userTparts[$y] . "<br />";
            };
        };
    };  
?>
</body> 
</html>

我发现不需要多维数组$citta所以我把它拿出来了。

请注意,此脚本会通过";"分解用户文本输入。您可能需要进行一些改进才能使用。

快乐编码。