Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 892707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:06:02+00:00 2026-05-15T14:06:02+00:00

I was dealing with refactoring of my small web app. all night. Today when

  • 0

I was dealing with refactoring of my small web app. all night. Today when I started testing, first bug what I found was problem with system PHP function nl2br().

On my localhost I have PHP version 5.2.9 and as I see on PHP site from version 4.0.5 nl2br() is XHTML compliant.

Then I absolutely don’t understand why does my nl2br() return <br> without second argument set to false instead of <br />.

Here is my method where I found this bug:

public function eliminateTags($msg) {
    $setBrakes = nl2br($msg);
    $decodeHTML = htmlspecialchars_decode($setBrakes);

    # Check PHP version
    if((int)version_compare(PHP_VERSION, '4.0.5') == 1) {
        $withoutTags = strip_tags($decodeHTML, '<br />');
    } else {
        $withoutTags = strip_tags($decodeHTML, '<br>');
    }

    return $withoutTags;
}
  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:06:03+00:00Added an answer on May 15, 2026 at 2:06 pm

    I’m not sure I understand what you’re trying to accomplish with this function. First of all you insert HTML breaks in every new line and then you strip all tags except the breaks.

    Wouldn’t it be more sensible to strip the tags first and then insert the HTML line breaks?

    public function eliminateTags($msg) {
        $decodeHTML = htmlspecialchars_decode($msg);
        $withoutTags = strip_tags($decodeHTML);
        $setBreaks = nl2br($withoutTags);
    
        return $setBreaks;
    }
    

    Edit:

    Apparently you are not using strip_tags() correctly. You need to ask PHP which tag to exclude, which is <br>, not <br />. Asking PHP to exclude<br /> is like asking to exclude, say, <p></p> which won’t work.

    Which in turn means you must not check for a PHP version – strip_tags() will work as is in all versions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I dealing with the next problem, I have a asp.net web project in which
I'm dealing with a problem the whole week already and can't find the answer
While dealing with JSON returned from YQL, I found myself looking for a way
I'm dealing with a weird bug that I don't manage to fix. It's a
When dealing with small projects, what do you feel is the break even point
My team has started to use selenium to do IE browser testing. One major
I'm dealing with the avatar problem. Because my forum is joined with another one.
I'm dealing 2 scripts in python. the first one needs to send a value
Dealing with some legacy code and in trying to get a poorly designed database
Dealing with Java - which the option you prefer in the most cases -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.