The Codesee The Codesee - 1 year ago 49
PHP Question

Adding a line break inside an element's value between two variables

I'm attempting to add a line break between two variables in the value of an


I've tried the script below (using the html tag
), however the value of the
field displays as
4 <br> body
(rather than a line break between the two variables).

$variable1 = '4';
$variable2 = 'body';

<input type="checkbox" value="'.$variable1.' <br> '.$variable2.'">

The reason I need a line break between the two variables is that further on in the script, the value of the
field is entered into a database and later on displayed (using
) and the space between the variables is required.

Is there a pure
solution to include a line break between the variables (rather than using

Answer Source

As per our discussion, the solution to the question turned out to use \n for a line break in HTML source and on screen being:

echo '<input type="checkbox" value="'.$variable1. "\n" . $variable2.'">'.$variable1.' <br> '.$variable2.'';

Resulting in:

<input type="checkbox" value="4
body">4 <br> body

and then using nl2br() on display.