0
編程分配,爲用戶創建一個文本區域,以便按文本行輸入,然後將文本打印到包含項目和項目編號的表格中。使用foreach循環將數組打印到表中。 html/php
該項目以換行符/返回字符結尾,項目數量應計算並顯示在表格中。
我相信我的問題是在foreach循環內的某個地方,但似乎無法找到解決方案。
任何幫助將非常感謝。
<!doctype html>
<META HTTPEQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<meta httpequiv="expires" content="0" />
<html lang="en">
<head>
<title> </title>
<link rel="stylesheet" href="hw7.css">
</head>
<body>
<?
$text = $_POST['stuff'];
$wordlist = explode("PHP_EOL", $text);
$wordcount = count($text);
print '<table>
<tr>
\t <th>Item Number</th>
\t <th>Item</th>
</tr>
';
//asort($wordlist);
foreach ($wordlist as $wordlists){
\t
print " \t <tr>
\t \t <td> $wordcount <br/> </td>
\t \t <td> $wordlists <br/> </td>
\t </tr>";
\t
print '</table>'; \t
}
\t
?>
</body>
</html>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<meta http-equiv="expires" content="0" />
<html lang="en">
<head>
<title> </title>
<link rel="stylesheet" href="hw7.css">
</head>
<body>
<section id="info">
Enter a list of valuse or text to sort in the textbox to the right. <br/> <br/>
<ul>
<li>Value sort will sort each individual line.</li> <br/>
<li>Text sort will sort each individual word.</li>
</ul>
</section>
<form action="hw7.php" method="post">
<section id="items">
<textarea rows="20" cols="40" name="stuff" >
</textarea> <br/>
<input type="submit" name="submit" value="Sort!">
</section>
</form>
</body>
</html>
'count($ text)'''不會返回字符串中單詞的數量。然而,它將返回數組中元素的數量。 – James