Welcome to WebmasterWorld Guest from 184.72.177.182

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

preg replace question

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

Full Member

10+ Year Member

joined:Feb 4, 2005
posts:205
votes: 0


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)

Senior Member

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

joined:Nov 12, 2005
posts:5966
votes: 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>
5:50 pm on Oct 9, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Feb 4, 2005
posts:205
votes: 0


Perfect! Thanks.