General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 1st, 2002, 02:28 PM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
How to use <pre> </pre> preformatted text

I want to output spaces and returns in an output view from a textbox in a form ... can I use the html <pre> for preformatted text inside a text box with php and a mysql database? Currently, all info added to text box is all smashed together when I display info., except for spaces between words. Return lines are ignored... any suggestions? A return line in html is <br> or <p>, I don't want users to have to enter code...


Hope I explained this okay. I have form users enter for Form Mail, but the text box info. is not very pretty when displayed. Any suggestions?
Thanks.
__________________
bow wow!

Reply With Quote
  #2  
Old November 1st, 2002, 02:36 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
This code works... you might want to wordwrap() the text though, because if you don't, the visitors can ruin your site layout by entering a very long word.. hope this helps

PHP Code:
<html>
<
head>
    <
title>Formatting Test</title>
</
head>

<
body>

<
form action="<?php echo $_SERVER['PHP_SELF'] ?>">
    <
textarea cols="40" rows="10" name="text"><?php echo $_GET['text'?></textarea><br>
    <input type="submit">
</form>

<pre><?php echo $_GET['text'?></pre>


</body>
</html> 


You can try out the code above at http://lindset.servehttp.com/pre_test.php
__________________
Best Regards,
Håvard Lindset

Last edited by Lindset : November 1st, 2002 at 02:39 PM.

Reply With Quote
  #3  
Old November 1st, 2002, 04:56 PM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I got it to work

I tried your advice but I was not posting back to myself, or maybe I didn't understand your message. Here is what I did to make it work..for me.

echo "<table width='500' border='1' align='left'>";
echo "<tr>";
echo "<td width='500' border='0' align='left'>";
echo "<h4>";
echo "<pre>";
echo $row["message"];
echo "</pre>";
echo "</h4>";[PHP]

Anyway, it will show the text as it is entered in the form, in "viewformpage" that I use for all sorts of functions. I have a school newsletter that teachers write, using a form, now they can just enter spaces and returns : ).

I have a rather long newsletter that spans several pages. One of those long winded teachers. But if gets ugly when his titles don't follow the coorisponding text. Any idea how to set the page to calculate the length of lines and put the rest on another (while it also takes with it the title to the textbox... maybe a "Title.cont." and the rest of the textbox) page.

They look fine online but when printing...yuck. I like the way this site has a print feature... anyone have the code for that?

Thanks for all everyones help.

Reply With Quote
  #4  
Old November 2nd, 2002, 12:06 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
You can also try using regular expressions:

PHP Code:
 ereg_replace("\n""<br>"$textarea_variable_name);
ereg_reaplce("\n\n""</p><p>"$textarea_variable_name); 


It will replace any linefeeds (when enter is pressed) with a <br> tag... And replaces the double linefeeds with a paragraph <p>.

Hope it helps.
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #5  
Old November 2nd, 2002, 12:48 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Quote:
Originally posted by FrankieShakes
You can also try using regular expressions:

PHP Code:
 ereg_replace("\n""<br>"$textarea_variable_name);
ereg_reaplce("\n\n""</p><p>"$textarea_variable_name); 


It will replace any linefeeds (when enter is pressed) with a <br> tag... And replaces the double linefeeds with a paragraph <p>.

Hope it helps.


nl2br()

Reply With Quote
  #6  
Old November 2nd, 2002, 01:07 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes


You got me! hehehe...

Reply With Quote
  #7  
Old November 3rd, 2002, 05:09 PM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
great help!

I tried my method my with the <pre> </pre> , but when I dropped in text from MsWord, it went across the page, since Word didn't require a return to go to next line, there were none. I tried inserting a wordwrap() to solve it, but the <pre></pre> took presidence over the wordwrap().

I'll try your suggestion FrankieS. And get back to ya with the answer. The wordwrap() works great if left alone, although it smashes it all together.

Anyone know a tutorial on making print friendly pages, like the tutorials on devscripts site?

I think the world of these tutorials, I print em out and have a personal ref. of em all. Great help!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > How to use <pre> </pre> preformatted text


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT