View Single Post
Old 12-11-2012, 07:21 AM   PM User | #5
shadowsai
New Coder

 
Join Date: Dec 2009
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
shadowsai is an unknown quantity at this point
Quote:
Originally Posted by Custard7A View Post
There are much better ways to preserve preformatted text, I'm sure. A line of nbsp's is a good way to tell you're doing something wrong. I suppose the proper method depends on what's happening with the data before it reaches the page (Passing through a database, etc).
Yes, I know that, however, I need to display all those extra spaces to preserve the formatting in each line.

Quote:
Originally Posted by Fou-Lu View Post
Agreed. Use CSS for your markup; assuming this is coming from some storage or input, you likely have an intent to display it in some relevant element block. Its as simple as forcing a pre whitespace:
PHP Code:
$s 'This     had 5 spaces';

printf('<span style="white-space: pre;">%s</span>'$s); 
Patterning this one is more of a pain than it looks. It would be trivial to replace multiple whitespace with a single &nbsp;, but more complex to perform many replacements for a single character that is in a multiple sequence. Use the preformat instead as its a lot easier and you needn't worry about the data for the medium that you are using.
Well, the problem is, I need to retain (and display) the original amount of spaces in the database. I can easily replace every single occurrence of " ", but I have no idea how to do this. The database structure exists (in MSAccess), I'm just converting the entire application to MySQL/PHP.

Would it work if I found all the consecutive spaces, count how many consecutive spaces there were, stored that number in a variable, and then called the replacement that many times?
shadowsai is offline   Reply With Quote