Forum Moderators: coopster

Message Too Old, No Replies

preg replace question

         

alphacooler

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!

eelixduppy

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



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>

alphacooler

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

10+ Year Member



Perfect! Thanks.