The following code outputs a b:
$var="a b"; // I inserted 3 white spaces, and HTML is rendering only one
echo $var;
The issue is that if I store $var in a table, it will KEEP the white spaces, and while reading, it strips them back. The striped data gets as it is updated in another table, resulting in mismatch of same values in both the tables.
I tried google search and found in a thread that its how HTML behaves. Any hope on how can I fix this?
The normal white-space behavior is to collapse everything to one space. You can modify it by changing the white-space:
css rule to white-space: pre;
or white-space: pre-wrap;
See https://developer.mozilla.org/en/CSS/white-space for more details
Multiple spaces are trimmed in the html output of most browsers, not in the html code itself. If you want multiple spaces to render you can use str_replace(" ", " ",$var)
which will tell the browsers to render each whitespace character. The same goes for multiple linebreaks, using nl2br()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With