By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,110 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,110 IT Pros & Developers. It's quick & easy.

I am having trouble using nl2br with htmlentities

P: 161
Ok, I want to disable any html tags, but the problem is when I do add in the nl2br function with a htmlentities it displays the tags for the <br>! I even keep seeing rn every time I enter a return in that area from the textarea html command. So how do I have nl2br going and htmlentities going at the same time, but not having to disabling each other?
Jul 17 '07 #1
Share this Question
Share on Google+
2 Replies

Expert 5K+
P: 5,821
Heya, Ajm.

Make sure you call the two functions in reverse order:
Expand|Select|Wrap|Line Numbers
  1. nl2br(htmlenitites($str));
instead of:

Expand|Select|Wrap|Line Numbers
  1. htmlenities(nl2br($str));
In terms of seeing 'rn' where your newlines go, make sure you use double quotes (e.g., "\r\n" instead of '\r\n'). PHP does not parse most control characters in single-quoted strings.
Jul 17 '07 #2

P: 161
Ok here is my code from what you posted does not work it is now going back to what I was avoiding:

[PHP]$message = nl2br(htmlentities(stripslashes(mysql_escape_strin g($_POST['message']))));[/PHP]

Here is what it is echoing out.
Jul 17 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.