Welcome to WebmasterWorld Guest from

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)

Full Member

10+ Year Member

joined:Feb 4, 2005
votes: 0

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 June 30, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
votes: 0

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.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members