Welcome to WebmasterWorld Guest from 54.204.100.232

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

preg_replace question

need to create an un-ordered list from carriage returns

   
8:04 am on Jun 30, 2006 (gmt 0)

10+ Year Member



I have a simple form where users enter one item per line then hit return and enter again, etc.

Once I pull up this text from the database, what sort of preg_replace could I do to turn each line into text surrounded by <li> </li>?

7:55 pm on Jun 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm, try using:


$text="I'm nobody! Who are you?
Are you nobody, too?
Then there's a pair of us don't tell!
They'd banish us, you know.
How dreary to be somebody!
How public, like a frog
To tell your name the livelong day
To an admiring bog!";
preg_replace("/(.+)\r{0,1}\n/", "<li>$1<\/li>\n", $text);

It may work, but I'm too lazy to test it now.