Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts

    Allowing/Disallowing HTML in Posts with PHP

    Hiya,

    I am building a forum and I want to allow non-premium members to be able to post simple messages, where they CANNOT post HTML, but when they hit enter twice, it records as a new paragraph. Obviously it does it as you type it out in the textarea, and it looks like this in the database, but when recalling it - it comes out as one long line.

    At the moment it allows HTML, and you would have to type in <P> to get a new paragraph... how do I stop html and yet allow the parapraph without typing <P>.

    Thanks in advance!
    Taylor.
    www.ysuperleague.com

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i would use:

    PHP Code:

    $str 
    htmlentities($strENT_QUOTE);
    $str nl2br($str); 

  • #3
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    just another thing i forgot to mention. nl2br() will convert newlines to <br />. If you need XHTML compliance but are using an earlier version of php, nl2br will stop your page validating because it will replace newlines with <br>.

    if your on an older version of php that does this, it can be overcame by:

    PHP Code:

    $str 
    preg_replace("\n"'<br />'$str); 

  • #4
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts

    Thanks!

    Hiya,

    Thanks for that - I assume though that this is just for allowing new lines/paragraphs... How do I stop HTML from being read altogether?

    Thanks in advance!
    Taylor.
    www.ysuperleague.com

    EDIT: Nevermind - I found out the easy way - by putting it in! LOL - Thanks!
    Last edited by Taylor_1978; 11-02-2003 at 06:51 PM.

  • #5
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok

    PHP Code:

    preg_replace
    ("/\\<([\\/]{,1}(.*))\\>/is"""$str); 
    try that.

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Posts
    161
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Hmmmmm

    I've never used it but isn't there a function called striptags()

  • #7
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes, you're right

    i searched php.net for strip_html

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Posts
    161
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Originally posted by missing-score
    yes, you're right

    i searched php.net for strip_html
    I mentioned that I'd never used it because I thought you might need the function do something different, I knew it actually existed.

    Glad I could help for once, I'm not exactly a PHP genius


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •