There's a simple way to include
when there's a new line in the database (nl2br), but is there anything similar for tabs?
I've tried different solutions which works in the way of the look, but not when you're copying the code. I've tried a CSS style and made it like:
#br{
margin-right: 30px;
float: left;
}
But once I copy the code, there's no tab. In my database there's a TAB, but how do I print the tab?
You can use a bit of CSS to display tabs as tabs.
#br {
white-space: pre-wrap;
tab-size: 4;
}
pre-wrap
is the best solution, I think, because it still allows the text to wrap normally when a line is full. pre
is also possible, but then the text won't break at the end of a line.
tab-size
is optional. By default it is set to 8 spaces, but you can change that by specifying a number of spaces in this property.
Note that I've copied your CSS selector, #br
, but normally I would make a class for this, so you can easily apply this style to any number of elements in your page.
Also note, since pre-wrap
also displays line breaks as actual breaks, you probably won't need to call nl2br
on the server anymore.
You can write a function like nl2br()
. Something like:
<?php
function tab2span($str){
if(strpos($str, "\t"){
$str = str_replace('\t','<span class="tabbed"> </span>',$str);
}
return $str;
}
?>
Then you can also adjust your CSS to style it better if you need.