Michdd Posted May 4, 2009 Share Posted May 4, 2009 Currently I use nl2br() to display the line breaks and what not from text taken from the database. But it seems when I just echo it out the 'tabs' don't show within it. Is there a separate function for this or what? Link to comment https://forums.phpfreaks.com/topic/156834-displaying-tabs/ Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Try using pre: <pre style="tab-interval: 5px;">content</pre> Not sure if other tags work. Link to comment https://forums.phpfreaks.com/topic/156834-displaying-tabs/#findComment-826104 Share on other sites More sharing options...
ionik Posted May 4, 2009 Share Posted May 4, 2009 By 'tabs' I presume you are taking about extra whitespace that is not being parsed out. nl2br will break all \n and the like into <br /> to form a linebreak the whitespace is going simply be a bunch of characters. Check with firebug and see if the characters are there, if they are not check to see if they are being striped anywhere (before sending them to the database) or when retrieving them Link to comment https://forums.phpfreaks.com/topic/156834-displaying-tabs/#findComment-826111 Share on other sites More sharing options...
Michdd Posted May 4, 2009 Author Share Posted May 4, 2009 The <pre style="tab-interval: 5px;"> kinda works but it messed with my template.. And no, they're not stripped anywhere. If I display this is a <textarea> then the tabs show fine. Edit: But if I look in the webpage source I can see the "tabs" the empty white space... I assume I could just do a str_replace.. but is there a better method? Something like: $variable = str_replace(' ', ' ', $variable); Works fine I'd just like to know if there's a better method. Link to comment https://forums.phpfreaks.com/topic/156834-displaying-tabs/#findComment-826131 Share on other sites More sharing options...
ionik Posted May 4, 2009 Share Posted May 4, 2009 This would be a bit better as it would check for a double space and replace it with 'space' this way you are not limiting yourself to only 'tabbed' spaces $variable = str_replace(' ', ' ', $variable); Link to comment https://forums.phpfreaks.com/topic/156834-displaying-tabs/#findComment-826172 Share on other sites More sharing options...
thebadbad Posted May 4, 2009 Share Posted May 4, 2009 You can do like this forum does, converting tabs to <pre style="display: inline;"> </pre> with <?php $variable = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $variable); ?> It's the only way to make the browser display the tab, AFAIK. Link to comment https://forums.phpfreaks.com/topic/156834-displaying-tabs/#findComment-826192 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.