answersLogoWhite

0

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

13y ago

What else can I help you with?

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 check if the MySQL is running?

To check if MySQL is running, you can use the command line. On Linux, you can execute systemctl status mysql or service mysql status to see the service status. On Windows, you can check the Task Manager for the MySQL service or use the command sc query MySQL. Additionally, you can try connecting to the MySQL server using the MySQL client with mysql -u username -p to see if it accepts connections.


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


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.


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 is a data line?

a line protected by data


What is a data line protector?

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 linear and nonlinear data?

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


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.


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.