Ask Sawal

Discussion Forum
Notification Icon1
Write Answer Icon
Add Question Icon

Pixie Griebe




Posted Questions



Wait...

Posted Answers



Answer


— First-line and later-line treatments should now be limited to 4 classes of medications: thiazide-type diuretics, calcium channel blockers (CCBs).


Answer is posted for the following question.

What is jnc 8 classification of hypertension?

Answer


You need to include a long string of text that needs to be broken by line breaks so it’s easy for your users to read. And so, you found yourself wondering…

What’s the best way to accomplish this?

To add new lines to a string in PHP, echo the string using the nl2br() function, adding \n wherever you want the lines inserted. The function will return a string with a
element inserted before every \n character.

It is as simple as that. If you haven’t used the nl2br() function (the name stands for “newline to break”), it takes a while to learn the ropes. In the rest of this post, I’m going to show you exactly how to use it.

PHP, like most other programming languages, has support for the “end of line” or “newline” character, which tells the interpreter to insert a newline in the output of your code.

This is done by using the nl2br() function. The function parses the string, looks for \n characters, then returns a new string with \n converted into
elements. In turn, the user’s browser converts the
elements into line breaks as it renders the DOM.

In the simplest implementation imaginable, your use of the nl2br() function would look like this:

The above function will return the following output:

It’s important to note the PHP also allows you to use \r, \r\n, and \n\r instead of \n for end of line characters. You can use these interchangeably, although—to make your code consistent and easy to debug—it’s a good idea to select one and stick to it.

So, whether you use this:

Or this:

Or, last but not least, this:

With the nl2br() function, it won’t necessarily make a difference.

Decisions, decisions… Which newline character should you use?

The \r is for “carriage return” and originates from the days when the paper carriage on typewriters and mechanical printers had to be slid back into position and rotated upward to start a new line. The \n stands for “newline” for a new line triggered by the “typist.”

Operating systems and programming languages in the early days of computing adopted both carriage return (\r), newline (\n), and the carriage return followed by newline (\r\n) as it was sequenced on typewriters.

Of course, each picked up a different one:

Nowadays, which one to use comes down to your personal preference. Carriage return keeps the mouse cursor on the existing line, whereas newline moves it to the new line.

With all that said, most of the programmers I know use \n for the languages that support it. Also, in terms of length, \n and \r require half the characters as \r\n and \n\r, so I see no reason to use the latter.

In PHP, there’s a reserved word called PHP_EOL. It’s basically a predefined constant that the PHP documentation describes as “The correct ‘End of Line’ symbol for this platform.”

PHP_EOL, as you will see in the code snippet below, eliminates the need to use the nl2br() function:

According to a user in this Stackoverflow thread, the purpose of PHP_EOL is to automatically choose the correct line break character so that your code is always compatible, no matter the operating system it’s run on.

That’s that. Though there are more ways to approach this, the nl2br() function and the PHP_EOL predefined constant should do the job, respectively, for HTML and non-HTML apps.

Let me know in the comments if you can think of any sleeker approaches, or if you’ve come across any limitations or edge cases of the above that are worth sharing with the rest of this post’s readers.


Answer is posted for the following question.

How to echo break in php?

Answer


How do I fix Msvcr110 dll errors on Windows 10? · Run a third-party DLL fixer · Download and install msvcr110 dll · Restore msvcr110 dll from the


Answer is posted for the following question.

How to msvcr110.dll fix?

Answer


The Lakshmi puja is performed in the evening to invite Goddess Lakshmi at home People pray and wish for peace, wealth and prosperity in their


Answer is posted for the following question.

How to laxmi puja at home?

Answer


Differential Pressure - PSID is the difference in static pressure as measured between two points at the same elevation located in two different locations within the system. Common measurement units are pressure per square inch differential (psid) or bar differential (bar/d).


Answer is posted for the following question.

What is psid in pressure?

Answer


  • Work to resolve old wounds.
  • Understand it's not about you.
  • Explore your passion and talents.
  • Spend time with people you admire.
  • Envision what you want your life to look like.
  • Don't limit yourself.
  • Get feedback and buy-in from trusted sources.

Answer is posted for the following question.

High vs standard vision insurance?


Wait...