Need Advise On Clever Algorithm

Reply

Join Date: Jul 2004
Posts: 57
Reputation: bwest is an unknown quantity at this point 
Solved Threads: 1
bwest's Avatar
bwest bwest is offline Offline
Junior Poster in Training

Need Advise On Clever Algorithm

 
0
  #1
Feb 23rd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 57
Reputation: bwest is an unknown quantity at this point 
Solved Threads: 1
bwest's Avatar
bwest bwest is offline Offline
Junior Poster in Training

Re: Need Advise On Clever Algorithm

 
0
  #2
Feb 23rd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,057
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 131
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Need Advise On Clever Algorithm

 
0
  #3
Feb 23rd, 2006
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.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 355
Reputation: DanceInstructor is an unknown quantity at this point 
Solved Threads: 14
DanceInstructor's Avatar
DanceInstructor DanceInstructor is offline Offline
Posting Whiz

Re: Need Advise On Clever Algorithm

 
0
  #4
Feb 23rd, 2006
Scrollbar appears for me in firefox 1.5.0.1
Clear Mind Hosting and Web Design

If I've helped you please consider adding to my reputation.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,057
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 131
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Need Advise On Clever Algorithm

 
0
  #5
Feb 23rd, 2006
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.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 57
Reputation: bwest is an unknown quantity at this point 
Solved Threads: 1
bwest's Avatar
bwest bwest is offline Offline
Junior Poster in Training

Re: Need Advise On Clever Algorithm

 
0
  #6
Feb 23rd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Need Advise On Clever Algorithm

 
0
  #7
Mar 4th, 2006
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]
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 1422 | Replies: 6
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC