Php echo textarea line break

I'm using an textarea to send text to my DB.

Screenshot of db:

When I'm reading from the DB it removes the line breaks, how can I keep them in $row['opmerkingen']?

asked Jun 14, 2011 at 14:00

1

When displaying text, use nl2br[] to convert newlines to
tags, i.e., instead of , use .

By default, browsers display newlines as spaces, therefore they have to be converted to
tags.

For those who find this useful - please consider using white-space: pre-line, suggested by Emil Vikström. I'm not a web guy anymore and easily can't verify this, but Boaz says in comments that it is supported by all modern browsers. If so, that should be preferred to using nl2br[].

answered Jun 14, 2011 at 14:01

binaryLVbinaryLV

8,8322 gold badges39 silver badges42 bronze badges

1

An alternative to nl2br is to make use of the CSS attribute white-space:

white-space: pre-line;

answered Jun 14, 2011 at 14:17

Emil VikströmEmil Vikström

88.4k15 gold badges134 silver badges170 bronze badges

1

I put as follows but not working with single quotes.

echo $row['text'].'\n';

Put the double quotes. Then worked.




When we getting data it is comming with \r\n. Also use the double quotes there.

answered May 21, 2013 at 13:02

Sumith HarshanSumith Harshan

6,0782 gold badges35 silver badges35 bronze badges

0

Not the answer you're looking for? Browse other questions tagged php html textarea or ask your own question.

    Table of contents
  • Add Line Break in PHP
  • How to add a line break within echo in PHP? [closed]
  • How to echo an input of an textarea with line breaks?
  • How To echo a line break in the browser?
  • How do I echo line breaks from a MySQL database?
  • How to add a new line within echo in PHP?
  • Php mysql storing line breaks in text area in database
  • PHP - How To Add Line Break in PHP

Add Line Break in PHP

# php 7.*

sun 
moon
#php 7.x
 
Sun 
 Moon
#php 7.x

Welcome to Delft
Have a great time here

How to add a line break within echo in PHP? [closed]

echo "Thanks for your email. /n  Your orders details are below:".PHP_EOL;
echo 'Thanks for your email. /n  Your orders details are below:'.PHP_EOL;
echo  "kings \n garden";
kings garden
echo  nl2br ["kings \n garden"];
kings
garden
so "\n" not '\n'
$myfile = fopen["test.txt", "w+"]  ;

$txt = "kings \n garden";
fwrite[$myfile, $txt];
fclose[$myfile];
 
kings
 garden
echo "Thanks for your email" ."
". "Your orders details are below:"
echo __["Thanks for your email.\n
\n
Your order's details are below:", 'jigoshop'];

Add Line Break in PHP

# php 7.*

sun 
moon
#php 7.x
 
Sun 
 Moon
#php 7.x

Welcome to Delft
Have a great time here

How to echo an input of an textarea with line breaks?

white-space: pre-line;
echo $row['text'].'\n';


How To echo a line break in the browser?

if [file_exists[$fName]] {
   echo "CreationTime: ".$CreationTime.
        "CurrentTime: ".$CurrentTime.
        "after ".[$fLifeTime]." Days from Creation: ".$fAge;
   }
if [file_exists[$fName]] {
   echo "CreationTime: ".$CreationTime. "
". "CurrentTime: ".$CurrentTime. "
" . "after ".[$fLifeTime]." Days from Creation: ".$fAge; }
 if [file_exists[$fName]] {
      echo "
";
       echo "CreationTime: ".$CreationTime. PHP_EOL .
            "CurrentTime: ".$CurrentTime. PHP_EOL .
            "after ".[$fLifeTime]." Days from Creation: ".$fAge;
       }
if [file_exists[$fName]] {
    echo "CreationTime: ".$CreationTime.
    "
CurrentTime: ".$CurrentTime. "
after ".[$fLifeTime]." Days from Creation: ".$fAge; }
if [file_exists[$fName]] {
   echo "CreationTime: ".$CreationTime.
        "CurrentTime: ".$CurrentTime.
        "after ".[$fLifeTime]." Days from Creation: ".$fAge;
echo "
"; //break to new line. }
if [!file_exists[$fName]] {
    $info = "CreationTime: " . $CreationTime . PHP_EOL .
        "CurrentTime: ". $CurrentTime . PHP_EOL .
        "after ". [$fLifeTime]." Days from Creation: " . $fAge;

    echo nl2br[$info];
}

How do I echo line breaks from a MySQL database?

while[$wallposts = mysql_fetch_assoc[$getwallposts]] {
    $postid = $wallposts['id'];
    $postedby_username = $wallposts['postedby'];
    $wallpostdate = $wallposts['dateposted'];
    $wallpost = $wallposts['post'];

    $querypostedby_info = mysql_query["SELECT * FROM `users` WHERE `username`='$postedby_username'"];

    //get the info above
    if [mysql_num_rows[$querypostedby_info]===1] {
        $getpostedby_info = mysql_fetch_assoc[$querypostedby_info];

        $postedby_id = $getpostedby_info['id'];
        $postedby_profilepicture = $getpostedby_info['profilepicture'];
    }

    //display the posts
    $wallpoststicker = 
    "
    
• $wallpostdate
$wallpost
"; }

How to add a new line within echo in PHP?

ABC

Chủ Đề