homepage Welcome to WebmasterWorld Guest from 107.21.163.227
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
preg_replace question
need to create an un-ordered list from carriage returns
alphacooler




msg:1273557
 8:04 am on Jun 30, 2006 (gmt 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>?

 

adni18




msg:1273558
 7:55 pm on Jun 30, 2006 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved