Reputation: 6471
<input type="hidden" name="status" class="status" value="
<?php if (!empty ($status)) {
echo $status;
} else {
echo "default";
} ?>"
/>
My result is:
<input type="hidden" name="status" class="status" value=" default">
My problem is: There is an empty space in value=" default"
And I cannot remove it. I cannot see, why it is there...
Upvotes: 1
Views: 49
Reputation: 472
Line breaks are validated as a space if in HTML scope. So you could, for example, place the opening PHP tag directly after value="
. Anyway, let me make this suggestion to improve your code:
<input (...) value="<?php echo !empty($status) ? $status : 'default'; ?>">
Shorthand if statements are pretty useful for these cases because they are compact and are, if you get used to them, very readable.
Please note, that since HTML5 you don't need the self-escaping (/>
) for tags that are marked as self-closing. the input
tag is one of them.
Upvotes: 1
Reputation: 254
Change
<input type="hidden" name="status" class="status" value="
<?php if (!empty ($status)) {
echo $status;
} else {
echo "default";
} ?>"
/>
To:
<input type="hidden" name="status" class="status" value="<?php if (!empty ($status)) {
echo $status;
} else {
echo "default";
} ?>"
/>
Upvotes: 2