Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

preg replace question



5:13 pm on Oct 9, 2006 (gmt 0)

10+ Year Member

I've got a preg_replace that tosses <li></li>'s around every new line. I know it works on windows machines, but I know the code doesn't account for any other systems.

$body = preg_replace("/\n/","</li><li>",$body);

What should I change here?



5:31 pm on Oct 9, 2006 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

The solution didn't work from your last thread [webmasterworld.com]?

Here's a full example:

$pattern = "/^(.+)$/m";
echo '<ul>';
echo preg_replace($pattern,"<li>$1</li>",$_POST['text']);
echo '</ul>';
<form method="post">
<textarea name="text"></textarea>
<input type="submit" />


5:50 pm on Oct 9, 2006 (gmt 0)

10+ Year Member

Perfect! Thanks.

Featured Threads

Hot Threads This Week

Hot Threads This Month