Welcome to WebmasterWorld Guest from 54.145.136.73

Forum Moderators: coopster & jatar k

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?

Thanks!

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

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



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

Here's a full example:


<?php
if(isset($_POST['text']))
{
$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" />
</form>
5:50 pm on Oct 9, 2006 (gmt 0)

10+ Year Member



Perfect! Thanks.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month