answersLogoWhite

0


Best Answer

In most raw (not formatted) text, such as the text in a simple HTML input element, new lines are denoted by a special "newline" character (commonly referred to as \n). When the text reaches this character, it pulls the text following it to the next line.

For example, the string "hello\nworld" would actually appear as:

hello

world

When you submit and retrieve text data in MySQL, it preserves these newline characters as they were originally entered. When you print them onto an HTML page, you may notice that newline characters do not seem to "work" as you could expect them to. The previous string would actually appear as "helloworld", instead of being broken up into two lines.

This is because the string is printed into the HTML source code as "hello\nworld". Browsers are supposed to ignore most whitespace and newlines, which would give us the resulting "helloworld".

In HTML, new lines are created with the
element. When pulling raw text data from MySQL, you will probably want to replace any occurrences of newline characters (which is the raw text's way of creating new lines) with the
element (which is HTML's).

A function exists which easily makes the replacements. It is the nl2br() function, which (simply put) accepts one string as an argument (the text data to replace newline characters) and returns a string (the text data with \n replaced as
).

Example:

$string_taken_from_mysql = 'hello \n\n hello';

echo nl2br($string_taken_from_mysql);

?>

Outputs:

hello

hello

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Learn bay

Lvl 8
2y ago

Use the newline characters 'n'or 'rn'to create new lines. To add a new line in the source code, use the PHP newline characters n or rn. You can use the PHP nl2br() function to insert HTML line breaks before all newlines in a string if you want the line breaks to be displayed in the browser as well.

To learn more about data science please visit- Learnbay.co

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you get the line breaks to work when you retrieve data from MySQL to PHP?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you insert data to a MySQL database?

To insert data in Mysql you have two ways. 1. GUI Mysql Client 2. Command line tool GUI mysql client like PHPMyAdmin, Heidisql is helpful to enter the data in tables.Mysql also provide the command line tool for performing the Mysql operations. Please refer links.


What type of database is MySQL?

MySQL databases are relational. A relational database does not store all the data in one large store, but stores the data in separate tables. It is an organized collection of data stored in tables that relate to others. It is optimal for extensive volumes of data. Depending on the type of database, the approach to its development, management and administration differs. A database management system can be very feature rich, but it also needs to be simple and fast. Database professionals can manage their DBMS manually through the command line, but it's easier and faster to complete tasks through a dedicated interface. One of the most popular of these is the tools of the dbForge MySQL product line, they can perform all tasks related to database development, administration, design, and maintenance, as well as data analysis and reporting. Among them, dbForge Studio for MySQL is the most multifunctional.


How do you find the MySQL version?

There are several ways to check your current version: From the command line Using Workbench Via MySQL Client, exp. using dbForge Studio for MySQL


How to add data to a mysql database one line at a time?

Yes, use a INSERT statement. ex: INSERT into person_table (id, first_name, last_name) VALUES (1, 'Fred', 'Flintstone');


What command is used to remove a table in MySQL?

Please refer to the related links section which points to the correct page of the on-line MYSQL manual.


What is a data line?

a line protected by data


I have installed MySql server and SQL Maestro for MySql.If i create a new database in mysql maestroit gives Sql access denied for rootlocalhost passwordno.how do i make a connection bween that.?

connect it using a cable line


What is a data line protector?

a line protected by data


What is linear and nonlinear data?

Data that makes a line Data that doesn't make a line


How do you export the database in MySQL?

In navicat you can export you database as a sql file. And on your server you can import it either by command line or phpMyAdmin.


What does line breaks mean in poetry?

Line breaks in poetry refer to the intentional placement of end-of-line breaks in a poem to create pauses, rhythm, or emphasis. Line breaks help to control the flow and pacing of a poem, allowing the poet to guide the reader's experience and interpretation of the text. They can also impact the visual presentation of the poem on the page.


What are the two breaks in HTML?

There are 2 types of breaks in HTML. One is the line break i.e. <br> and the horizontal line break <hr>.