Skip to content Skip to sidebar Skip to footer

Innerhtml Linebreaks With A String That Is Very Long With Line Breaks, Coming From A Mysql Query

I have a for loop in which I am printing out content on a web page. Anything with a line break in the database will not work with innerHTML. Here is the process of how to get a st

Solution 1:

Use following functions:

  • htmlentities:Convert all applicable characters to HTML entities
  • nl2br Inserts HTML line breaks before all newlines in a string

Or maybe change your sql query with TRIM function as used in link

Solution 2:

Use backtick character ( ` ) for multiline string in javascript.

use this line { Replace backtick with ( ` ) }

var str = backtick <?php echo $comment['contents'];? > backtick ;

insted of this line

var str = '<?php echo $comment['contents'];? >';

Post a Comment for "Innerhtml Linebreaks With A String That Is Very Long With Line Breaks, Coming From A Mysql Query"