Jump to content

[SOLVED] HTMLentities not showing hard returns/line breaks?


spiceydog

Recommended Posts

I'm sure there's an easy way around this but I have some forums that I made and I want users to be able to organize there posts with line breaks but I still do want want to give them the power to post html in there posts.

 

Currently I have the posting setup so when you post it runs an nl2br on the post and then when it echos the post it does a str_replace("<br />", "\r", $post) but that doesn't work.

 

i hope that makes sense. im really bad with the wording that scripters use lol.

Do you mean...

 

but I still do NOT want want to give them the power to post html in there posts.

 

If so, there is no real way to add space to text on a web page without using HTML.  You could use a crap ton of

 

Currently I have the posting setup so when you post it runs an nl2br on the post ...

nl2br converts new lines to <br /> for you. Use nl2br when you're getting data out of the database. Not when you are inserting it into the database.

 

I don't Understand what you mean by

... and then when it echos the post it does a str_replace("<br />", "\r", $post) but that doesn't work.

or to make things really complicated. wouldnt this not work?

 

<?php
// Function:
function nls2p($str)
{
  return str_replace('<p></p>', '', '<p>' 
        . preg_replace('#([\r\n]\s*?[\r\n]){2,}#', '</p>$0<p>', $str) 
        . '</p>');
}

// In Context:
<?php
echo nl2br(nls2p("Paragraph1\n\nParagraph2\n line1\n line2\n"));
?>
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.