The Codesee The Codesee - 7 months ago 12
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

input
field.

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

<?php
$variable1 = '4';
$variable2 = 'body';

echo'
<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
input
field is entered into a database and later on displayed (using
SELECT
) and the space between the variables is required.

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

Answer

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.