944,074 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1561
  • PHP RSS
Feb 23rd, 2006
0

Need Advise On Clever Algorithm

Expand Post »
Ok, I am putting my users text onto the screen. I need it to represent what they typed so I use the <pre></pre> tags to preserve the hard returns and other white space. The problem comes when they type a long paragraph (such as the one Im typing now) and the pre tags allow the text to stretch the whole website out. I know I can remove the <pre> tags and the text will wrap inside the table cell I place it in, but I need the hard returns and such preserved as I said. Is there an existing algorithm that solves this.

I notice that some sites will add hard returns to the users text to force it to all fit in some desired area. How do I do that.

I am asking in this forum because if I do need a complex algorithm it will need to be php as that is my development environment

Thanks in advance

-Brad
Similar Threads
Reputation Points: 14
Solved Threads: 1
Junior Poster in Training
bwest is offline Offline
57 posts
since Jul 2004
Feb 23rd, 2006
0

Re: Need Advise On Clever Algorithm

Well after doing more research. (Actually I did a view source on this page) to see how daniweb does it and they just replace the hard return characters with <br> tags. Thanks anyways
Reputation Points: 14
Solved Threads: 1
Junior Poster in Training
bwest is offline Offline
57 posts
since Jul 2004
Feb 23rd, 2006
0

Re: Need Advise On Clever Algorithm

What I do is wrap it in a div tag with the overflow attribute: <div style="overflow-x:auto; width:500px">

It works like this:

ThisIsReallyLongText_ThereAreNoSpaces_ItActsLikePRE_ThisIsReallyLongText_ThereAreNoSpaces_ItActsLikePRE_ThisIsReallyLongText_ThereAreNoSpaces_ItActsLikePRE_ThisIsReallyLongText_ThereAreNoSpaces_ItActsLikePRE_

A horizontal scroll will automatically be added in Internet Explorer. In Firefox, the text will just overflow out of its container. However, I believe this is a bug which is expected to be fixed in the next release.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is online now Online
13,646 posts
since Feb 2002
Feb 23rd, 2006
0

Re: Need Advise On Clever Algorithm

Scrollbar appears for me in firefox 1.5.0.1
Reputation Points: 17
Solved Threads: 14
Posting Whiz
DanceInstructor is offline Offline
355 posts
since Feb 2005
Feb 23rd, 2006
0

Re: Need Advise On Clever Algorithm

Well so they do! Good. It's a feature I have built into all of the posts so that if a horizontal scrollbar is required, one is automatically added, without stretching the site layout.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is online now Online
13,646 posts
since Feb 2002
Feb 23rd, 2006
0

Re: Need Advise On Clever Algorithm

Thanks cscgal, I saw that bit of html in your forum when I looked at the source I didnt know what it was for but good to know
Reputation Points: 14
Solved Threads: 1
Junior Poster in Training
bwest is offline Offline
57 posts
since Jul 2004
Mar 4th, 2006
0

Re: Need Advise On Clever Algorithm

Quote originally posted by bwest ...
Well after doing more research. (Actually I did a view source on this page) to see how daniweb does it and they just replace the hard return characters with <br> tags. Thanks anyways
Exactly the solution I use, bwest.
[PHP]$mystr = str_replace("\n","<br />",$mystr);[/PHP]
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Need some help with parsing an XML file
Next Thread in PHP Forum Timeline: Session





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC