This question already has answers here:
Preserve Line Breaks From TextArea
(7 answers)
Closed 4 years ago.
This is inside the phpmyadmin:
This is the output after echo:
and this is the code for display output
$joinEvent = mysqli_query($db, "SELECT * FROM event WHERE event.eventID='".$_GET['eventID']."'");
while($row = mysqli_fetch_array($joinEvent))
{
$joinDetails = $row['details'];
}
<p align="justify"><?php echo $joinDetails; ?></p>
How do I echo exactly what user enter in the input?
Use nl2br() when you output to the screen, change your current code to:
<p align="justify"><?php echo nl2br($joinDetails); ?></p>
It might be better for you to store your details column as a text datatype.
Read here: What is the MySQL VARCHAR max size?
Your result is actually exactly what the user input is ; except that in HTML, line break characters (\r\n \n and so) are not interpreted by the browser. As said in the comments, you'll have to use the PHP function nl2br() to convert your line break characters to <br /> tags, which are the HTML line breaks.
Related
This question already has answers here:
Preserve Line Breaks From TextArea
(7 answers)
Closed 4 years ago.
In my PHP file I am able to retrieve text from my MySQL database, but it isn't in the same format when I echo it.
The image attached shows how the text is in the database, and how I want it to be echoed.
But instead, it echoes it without the line breaks. How can I keep the format?
Use the <pre> tag to output pre-formatted text, so it won't be reformatted:
echo "<pre>" . $row['content'] . "</pre>";
Or use the nl2br() function to convert newlines to HTML:
echo nl2br($row['content']);
This question already has answers here:
How can I replace newline or \r\n with <br/>?
(10 answers)
Closed 5 years ago.
I read a text from my database which has multiple lines and and stored in a variable.
when I output this variable on my webpage it is printed all in one line.
How do output in different lines.
<?php
$num=$_GET['id'];
$result=mysql_query("SELECT * FROM messages WHERE id='$num'");
$row=mysql_fetch_array($result);
$msg=$row['message'];
?>
message:<br/><?php echo $msg;?>//Here I need to print message in multiple
//lines as entered in the database.
If you want to show the Exact Message as fetched from the database, Use <pre> tag!Example:
<?php
$num=$_GET['id'];
$result=mysql_query("SELECT * FROM messages WHERE id='$num'");
$row=mysql_fetch_array($result);
$msg=$row['message'];
?>
message:<br/><?php echo "<pre>$msg</pre>";?>
Hope that helps!
Suggestion : Try not to use mysql_* functions as they are Deprecated now! Instead, Use PDO. It will save your script from SQL Injection too!
This question already has answers here:
how to show the content exactly as it's saved in mysql
(4 answers)
Closed 6 years ago.
I have a form with an input textbox that stores the content in the mysql database.
For example, I write in the input box:
Hello World!
Here is the new line
In the database, I find exactly the same text without any special characters ("here is..." starts in a new line in the database too).
When I call this data in a php echo, it shows it as:
Hello World! Here is the new line
What's wrong? How can I fix it? thanks
You need to pass the database string to nl2br fucntion to get the new line as break rule in HTML.
<?php
$dbSQLValue = "Hello World!\nHere is the new line"; //string retrieved from SQL
echo nl2br($dbSQLValue);
?>
New lines are not converted directly to HTML break line.
Hope this helps.
Open page source in browser and see that newlines are there, but for the browser to display them - they should not be \ns, but <br> tags or be inside a <pre> tag.
So: either convert newlines to brs via nl2br($your_var) or put the whole echo inside a <pre>.
This question already has answers here:
Preserve Line Breaks From TextArea
(7 answers)
Closed 7 years ago.
I tried this but it's not chaning new lines to < br >
<textarea name="addesc" id="addesc"><?php echo $data['addesc']; ?></textarea>
$data['addesc'] = preg_replace("/\r\n|\r/", "<br />", $_POST["addesc"]);
$data['addesc'] = trim($data['addesc'])
As such there's no $_POST["addesc"] on the post.php page. There's $_POST["do"]. I tried it too. No results.
There is a php function for that called nl2br.
Btw. searching for "new line to br" would have been very easy and brings up certain related topics on SO and the php manual of nl2br:
How to replace \r & \n with <br/>?
This question already has answers here:
Preserve Line Breaks From TextArea
(7 answers)
Closed 10 years ago.
I have a form containing text area. I am entering text in this manner -
Hi Dear,
How are you .
Just reply when you get my message.
I am using mysql database, in that its storing the same manner.
But when I am displaying it, its just displaying in single line.
like -
Hi Dear, How are you . Just reply when you get my message.
But I don't want it like this, I want to display it in the same manner as it stored in the database.
If anyone know the solution of this reply me please.
Thank you
Since you are displaying this in a text area, and this lines are stored as a single value in the db, then they should be ended by <br /> like this:
Hi Dear, <br />
How are you .<br />
Just reply when you get my message.
You need to replace
\n\r or \n or \r
By:
<br />
PHP function:
nl2br()
ELSE
$content = str_replace("\r\n", "<br />", $content);
Use the php function nl2br($input) on your text input before it goes into the database. It will replace line breaks with <br /> tags.