Jump to content

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


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"));
?>
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.