offsprg01 Posted February 7, 2007 Share Posted February 7, 2007 ok so here's the set up i'm taking entries from a db the client has provided and showing them in the web page. only problem is the client use tab and returns to format the text and we al know that won't work in html so..... i need to take the white space and turn it in to html. anybody have any scripts i could use to do that? i haven't the slightest clue where to start. i've been trying google for hours now but mu goggle fu is failing me. any help would be appreciated. here's a link to an example. http://www.harwoodmarketinggroup.com/WIP/aboutGrande/pressroomdetials.php?recordID=3058&YEAR=2003&QUARTER=04 Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 7, 2007 Share Posted February 7, 2007 $str = str_replace(' ', ' ', $str); Not sure if htmlentities() or a similar function would be better, but that should work. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 7, 2007 Share Posted February 7, 2007 I think you'll have more success wrapping the text inside of pre HTML tags. Also, use CSS to give the font a fixed width for best results. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 7, 2007 Share Posted February 7, 2007 Good call roopurt Quote Link to comment Share on other sites More sharing options...
offsprg01 Posted February 7, 2007 Author Share Posted February 7, 2007 ok so that takes care of spaces, but what about paragraphs? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 7, 2007 Share Posted February 7, 2007 I should also warn that text inside of pre tags will stretch page elements wide even if they have a CSS width attribute. You can use PHP's wordwrap() function to get around this. I've not tried it, but I would guess using the CSS overflow, or whatever it is, property might fix it as well. Quote Link to comment Share on other sites More sharing options...
offsprg01 Posted February 7, 2007 Author Share Posted February 7, 2007 ok so i got the pre tags to work but the htmlentites() gives be things like <bold></bold> not the formatted text. here the line of code < p ><p r e><?php echo wordwrap(htmlentities($row_DetailRS1['Body'])); ?></p r e>< / p > Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 7, 2007 Share Posted February 7, 2007 So...don't use htmlentities. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 7, 2007 Share Posted February 7, 2007 htmlentities replaces certain characters with their HTML encoded equivalents. For example: < is converted to < > is converted to > & is converted to & Remove the call to htmlentities as that's not what you want in this case. Quote Link to comment Share on other sites More sharing options...
offsprg01 Posted February 7, 2007 Author Share Posted February 7, 2007 well then how do i get the bold stuff to format correctly without htmlentites() sorry if this problem is trivial but i've never had this issue before so i am not used to converting preformatted text at run time. so here's my thiking if htmlentites() returns <bold></bold> why doesn't the browser execute the html commands like it does if i just echo out a var that is equal to <bold>some text</bold> Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 7, 2007 Share Posted February 7, 2007 Because its < b >some text< /b > without the spaces. Quote Link to comment Share on other sites More sharing options...
offsprg01 Posted February 7, 2007 Author Share Posted February 7, 2007 :doh: thats what i ment. but when i remove the html entities i don't get the bold text either. also is there anyway to fix the pre tags so they won't make the kerning all equal. i know the art director is not going to go for it the way it is. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 7, 2007 Share Posted February 7, 2007 Look at the HTML source given to your browser and make sure it's what you're expecting. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 7, 2007 Share Posted February 7, 2007 There's the HTML from your example. <pre><bold>Grande Communications Leads Corporate Partners to Provide Meals to Corpus Christi Youth</bold> Quote Link to comment Share on other sites More sharing options...
offsprg01 Posted February 7, 2007 Author Share Posted February 7, 2007 just did look at it. i guess i'll have to write a simple script to replace <bold> with <b> ect ect and one more question fixed-width characters. is thre anyway to make them not so inside the pre tag? the art director is not going to like them. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 7, 2007 Share Posted February 7, 2007 <pre style="font-family: enter_a_non_fixed_width_font_family;">some text</pre> Quote Link to comment Share on other sites More sharing options...
offsprg01 Posted February 7, 2007 Author Share Posted February 7, 2007 well got the thing fixed by adding < p >< p r e style="font-family:Arial, Helvetica, sans-serif"><?php echo wordwrap($row_DetailRS1['Body']); ?>< / p r e >< / p > Quote Link to comment Share on other sites More sharing options...
offsprg01 Posted February 8, 2007 Author Share Posted February 8, 2007 heheh guess we were posting at the same time. thanks for the help man. you are my new hero for today. Quote Link to comment Share on other sites More sharing options...
offsprg01 Posted February 8, 2007 Author Share Posted February 8, 2007 oops well get an issue. the wordwrap still wraps as if the font were fixed-width. ie it breaks the lines at the same places regardless of where they should break with the new font. now the line only go about half way across the page. Quote Link to comment Share on other sites More sharing options...
offsprg01 Posted February 8, 2007 Author Share Posted February 8, 2007 got is fixed i added this to the style sheet. pre { white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ } Quote Link to comment Share on other sites More sharing options...
offsprg01 Posted February 8, 2007 Author Share Posted February 8, 2007 ok so i have two new issues. pre { text-align: justify; } is not working on the pre tags. it's defaulting to left align. i can use pre { text-align; right; } however and it align every thing to the right. does anyone know how to make the text justify? also: safari 1.3 completely ignores the word wrap. is there any work around for that? i cannot use php's wordwrap() as it is applied before the css font styling and thus make the words wrap as if they were still a fixed width font, resulting the the text only going half way across the page before it breaks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.