468,469 Members | 1,952 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,469 developers. It's quick & easy.

I am having trouble using nl2br with htmlentities

Ajm113
161 100+
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
2 3081
pbmods
5,821 Expert 4TB
Heya, Ajm.

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

Expand|Select|Wrap|Line Numbers
  1. htmlenities(nl2br($str));
  2.  
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
Ajm113
161 100+
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.
Line1rnLine2rn
Jul 17 '07 #3

Post your reply

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

Similar topics

4 posts views Thread by Marco | last post: by
11 posts views Thread by Jakanapes | last post: by
3 posts views Thread by jl | last post: by
2 posts views Thread by matthud | last post: by
2 posts views Thread by shotokan99 | last post: by
matheussousuke
5 posts views Thread by matheussousuke | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.