Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

textarea

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 I would need the output from the field to be something like this:

<li>some.url.com</li>
<li>some.url.com</li>
<li>some.url.com</li>
<li>some.url.com</li>
<li>some.url.com</li>

Does anyone know who to achive this with PHP please?

like image 854
Brigante Avatar asked Dec 05 '22 01:12

Brigante


1 Answers

$textareaData = '<li>'.str_replace("\n","</li>\n<li>",trim($textareaData,"\n")).'</li>';

EDIT

Modified to get rid of all blank lines as well:

$textareaData = '<li>'.str_replace(array("\r","\n\n","\n"),array('',"\n","</li>\n<li>"),trim($textareaData,"\n\r")).'</li>';
like image 129
Mark Baker Avatar answered Jan 07 '23 04:01

Mark Baker