Convert comma separated string into list [closed]
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I have a string eg: $string = "word1,word2,word3,word4"; I need to echo this into <li> elements using PHP. So $string becomes: <li>word1</li> <li>word2</li> <li>word3</li> <li>word4</li> 回答1: Like this: $string = "word1,word2,word3,word4"; $string = explode(",",$string); foreach ($string as $str) { echo "<li>".