我设法得到不同行上显示的单词数量,我需要在“ - ”之间用单词旁边的每个单词的字符数。我怎么能这样做?
字符串来自textarea:“我喜欢苹果,但有时我吃香蕉”
$words = explode(" ", $_POST['txt']);
for ($i=0; $i<count($words); $i++){
echo "<br/>" . $words[$i] . " - ";}
显示:
i -
like -
apples -
but -
sometimes -
i -
eat -
bananas -
答案 0 :(得分:5)
没有办法回答这个问题,听起来不像是聪明的屁股,但...... strlen
......
答案 1 :(得分:4)
foreach(explode(" ", $_POST['txt']) as $word)
echo $word." - ".strlen($word)."<br>";
答案 2 :(得分:2)
$words = explode(" ", $_POST['txt']);
for ($i=0; $i<count($words); $i++){
echo "<br/>" . $words[$i] . " - " . strlen($words[$i]);
}