Adding a line break in MySQL INSERT INTO text

后端 未结 10 2089
太阳男子
太阳男子 2020-12-07 22:07

Could someone tell me how to add a new line in a text that I enter in a MySql table?

I tried using the \'\\n\' in the line I entered with INSERT I

10条回答
  •  温柔的废话
    2020-12-07 22:19

    1. You have to replace \n with
      before inset into database.

      $data = str_replace("\n", "
      ", $data);

      In this case in database table you will see
      instead of new line.

      e.g.

      First Line
      Second Line

      will look like:

      First Line
      Second Line

    2. Another way to view data with new line. First read data from database. And then replace \n with
      e.g. :

      echo $data;
      $data = str_replace("\n", "
      ", $data);

      echo "

      " . $data;

      output:

      First Line Second Line

      First Line
      Second Line


      You will find details about function str_replace() here: http://php.net/manual/en/function.str-replace.php

提交回复
热议问题