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

  • Home
  • SEARCH
  • 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 8895183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:42:32+00:00 2026-06-14T23:42:32+00:00

When converting new line characters to HTML break ( <br> ) What is Cleaner

  • 0

When converting new line characters to HTML break (<br>)

What is Cleaner to use?

str_replace(array("\r\n", "[br]", "\r"), '<br>', $Content);

OR

str_replace("\r\n", '<br>', $Content);
str_replace("[br]", '<br>', $Content);
str_replace("\r", '<br>', $Content);

I’ve been using the first method, but a friend of mine said that the way I currently use is more sloppy in terms of processing.

I’m using the formatting in a function; so

function Formatting ($Content)
{
 $Content = str_replace(array("\r\n", "[br]", "\r"), '<br>', $Content);
 return $Content;
}
  • 1 1 Answer
  • 0 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-06-14T23:42:33+00:00Added an answer on June 14, 2026 at 11:42 pm

    I would tweak this one myself (from the user notes in the manual page http://php.net/manual/en/function.nl2br.php:

    <?php
    /**
     * Converts newlines and break tags to an
     * arbitrary string selected by the user,
     * defaults to PHP_EOL.
     *
     * In the case where a break tag is followed by
     * any amount of whitespace, including \r and \n,
     * the tag and the whitespace will be converted
     * to a single instance of the line break argument.
     *
     * @author Matthew Kastor
     * @param string $string
     *   string in which newlines and break tags will be replaced
     * @param string $line_break
     *   replacement string for newlines and break tags
     * @return string
     *   Returns the original string with newlines and break tags
     *   converted
     */
    function convert_line_breaks($string, $line_break=PHP_EOL) {
        $patterns = array(   
                            "/(<br>|<br \/>|<br\/>)\s*/i",
                            "/(\r\n|\r|\n)/"
        );
        $replacements = array(   
                                PHP_EOL,
                                $line_break
        );
        $string = preg_replace($patterns, $replacements, $string);
        return $string;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am busy converting a query using the old style syntax to the new
I have a method that scans a string, converting any new lines to <br>
I am converting a JSON file to a plist using the new NSJSONSerialization class
Possible Duplicate: Converting ereg expressions to preg I am totally new to parsing a
I'm pretty new to jQuery, and I am converting a page from regular javascript
Using the new version of the substance look and feel for Java, the connecting
I'm new to coffeescript, and while there is extensive information concerning the proper method
When converting a project (in which a template method of IComparable was used a
Is converting a file to a byte array the best way to save ANY
Different platforms use different line separator schemes (LF, CR-LF, CR, NEL, Unicode LINE SEPARATOR,

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.