怎样table循环将它们输出啊,现在运行结果就一个you 3
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1 //EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml"><head>
<title> word_table.php </title>
</head><body>
<?php
function splitter($str) {// Create the empty word frequency array
$freq = array();// Split the parameter string into words
$words = preg_split("/[ .,;:!?]\s*/", $str);// Loop to count the words (either increment or initialize to 1)
foreach ($words as $word) {
$keys = array_keys($freq);
if(in_array($word, $keys))
$freq[$word]++;
else
$freq[$word] = 1;
} return $freq;
} #** End of splitter// Main test driver $str = "apples are good for you, or don't you like apples?
or maybe you like oranges better than apples";// Call splitter $tbl = splitter($str);
?><div>
<table border = "border">
<tr align = "center">
<td>word</td>
<td>frequency</td>
</tr> <?php
$sorted_keys = array_keys($tbl);
sort($sorted_keys);
foreach ($sorted_keys as $word);
?> <tr align = "center">
<td><?php print("$word"); ?>
</td>
<td><?php print("$tbl[$word]"); ?>
</td>
</tr> </table>
</div>
</body>
</html>
php
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1 //EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml"><head>
<title> word_table.php </title>
</head><body>
<?php
function splitter($str) {// Create the empty word frequency array
$freq = array();// Split the parameter string into words
$words = preg_split("/[ .,;:!?]\s*/", $str);// Loop to count the words (either increment or initialize to 1)
foreach ($words as $word) {
$keys = array_keys($freq);
if(in_array($word, $keys))
$freq[$word]++;
else
$freq[$word] = 1;
} return $freq;
} #** End of splitter// Main test driver $str = "apples are good for you, or don't you like apples?
or maybe you like oranges better than apples";// Call splitter $tbl = splitter($str);
?><div>
<table border = "border">
<tr align = "center">
<td>word</td>
<td>frequency</td>
</tr> <?php
$sorted_keys = array_keys($tbl);
sort($sorted_keys);
foreach ($sorted_keys as $word);
?> <tr align = "center">
<td><?php print("$word"); ?>
</td>
<td><?php print("$tbl[$word]"); ?>
</td>
</tr> </table>
</div>
</body>
</html>
php
foreach ($sorted_keys as $word) {
?> <tr align = "center">
<td><?php print("$word"); ?>
</td>
<td><?php print("$tbl[$word]"); ?>
</td>
</tr>
<?php } ?>
</table>