How to wrap each new line in textarea with li tags? PHP

前端 未结 3 1665
说谎
说谎 2021-02-10 18:15

I have a textarea form field where users will put URL\'s separated by a new line. Would it be possible to wrap each line from this textarea field with < li > tags?

So

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-10 18:24

    $textareaData = '
  • '.str_replace("\n","
  • \n
  • ",trim($textareaData,"\n")).'
  • ';

    EDIT

    Modified to get rid of all blank lines as well:

    $textareaData = '
  • '.str_replace(array("\r","\n\n","\n"),array('',"\n","
  • \n
  • "),trim($textareaData,"\n\r")).'
  • ';

提交回复
热议问题