douzheren3349
2015-06-30 12:18
浏览 32
已采纳

php处理字符串并在ul中回显它[关闭]

so i have got this string:

<?php
$elements = "first, second, third, fourth, fifth";
?>

And i'd like it to be echoed out like this:

<ul>
<li>first</li>
<li>second</li>
<li>third</li>
<li>fourth</li>
<li>fifth</li>
</ul>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dpafea04148 2015-06-30 12:26
    最佳回答

    Try this, it may help you issue;

     <?php 
    
    $elements = "first, second, third, fourth, fifth";
    
    $numbers = explode(", ", $elements);
    
    echo "<ul>";
    
    foreach ($numbers as $number) {
        echo "<li>{$number}</li>";
    }
    
    echo "</ul>";
    
    ?>
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题