Reputation: 193
I'm new in PHP coding which now I face the problem that the data that I stored in MYSQL have "Line Break" involved like this pic
But when I call them to show in table, it has no "Line Break" like this pic
As you can see in fourth and fifth block, the "Line Break" are not involved. (The third block is miracle, I don't know why but in other row it is as same as fourth and fifth block) I have no idea why, how to fix this?
This is my code, which normal echo them in table.
<tr>
<td align="center"> <?php echo $PositionName; ?> </td>
<td align="center"> <?php echo $Quantity; ?> </td>
<td align="center"> <?php echo $JobDescription; ?> </td>
<td align="center"> <?php echo $JobQualification; ?></td>
<td align="center"><?php echo $SkillRequired; ?></td>
<td align="center"> <?php echo $Salary; ?></td>
</tr>
Upvotes: 3
Views: 2565
Reputation: 7065
In HTML new line characters i.e. \n
characters are not printed.
PHP's nl2br() function will convert new lines \n
to <br/>
tag so that it takes appropriate line breaks.
Example:
<?php echo nl2br($JobDescription); ?>
Upvotes: 3
Reputation: 331
Use <?php echo nl2br($var); ?>
to convert new lines to HTML line breaks.
Upvotes: 1
Reputation: 405
Try printing your string using nl2br() PHP function.
<tr>
<td align="center"> <?php echo $PositionName; ?> </td>
<td align="center"> <?php echo $Quantity; ?> </td>
<td align="center"> <?php echo nl2br($JobDescription); ?> </td>
<td align="center"> <?php echo $JobQualification; ?></td>
<td align="center"><?php echo $SkillRequired; ?></td>
<td align="center"> <?php echo $Salary; ?></td>
</tr>
Upvotes: 4