Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 13th, 2004, 04:50 AM
Registered User
 
Join Date: Jul 2004
Location: Cape Town, , South Africa.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Paragraph marks

Hi all

I enter information on a page in a "textarea" and can then post to a different page. On the subsequent page I want to store the information in a mysql database with paragraph i.e. "\n" marks. Is there anyway I can get the paragraph formatting into the MYSQL database? When I retrieve the text from the database and put it into the html it doesn't save the line breaks. The line breaks only appear if I put the text into a "textarea" again.

Is there no way way of storing the information from a textarea and putting it into a mysql database and then outputting the information to html (without the use a textarea) and still maintaining the line breaks?

The code i used to test it is as follows...

linetest.php >>>>>>

<html>
<head>
  <title>Test</title>
</head>
<body>
  <form action="linetest1.php" method="post"> <table border="0">
      <tr> <td>Action Plan</td> <td>
      <textarea rows="10" name="ActionPlan"></textarea></td></tr>
    </table> <input type = "submit" value = "now"> </form>
</body>
</html>

linetest1.php >>>>>>>>>>>>>

<?php

  $new_actionplan = addslashes($HTTP_POST_VARS['ActionPlan']);
  echo 'The action plant is: '.$new_actionplan.' </br>';
  echo '<textarea>'.$new_actionplan.'</textarea>';

?>

The output is firstly the text without line breaks. Then the output is a textarea with the text inside. In the second instance the text has linebreaks. I would like the text with linebreaks outside of a textarea.

Any hints would be helpful.
Reply With Quote
  #2 (permalink)  
Old December 13th, 2004, 05:10 AM
Authorized User
 
Join Date: Oct 2004
Location: Edinburgh, Scotland, United Kingdom.
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

Try the combination "\r\n"



Many shoes,

Jamez/SiliconFuRy
Reply With Quote
  #3 (permalink)  
Old December 13th, 2004, 06:57 AM
Registered User
 
Join Date: Jul 2004
Location: Cape Town, , South Africa.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Jamez

Where would I put the "\r\n"?

Sameer
Reply With Quote
  #4 (permalink)  
Old December 13th, 2004, 07:55 AM
Authorized User
 
Join Date: Oct 2004
Location: Edinburgh, Scotland, United Kingdom.
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

in the file...

linetest1.php >>>>>>>>>>>>>

<?php

  $new_actionplan = addslashes($HTTP_POST_VARS['ActionPlan']);
  echo 'The action plant is: '.$new_actionplan.' </br>';
  echo '<textarea>'.$new_actionplan.'</textarea>';

?>

IF you look at the markup of that page (load it in the browser, file->view source) then you'll see the outputted text outside of the textarea is linebroken. You need to do a string replace for "\n" with "<br>" or "<p>" if you want the linebreaks to be shownin the html output.

Many shoes,

Jamez/SiliconFuRy
Reply With Quote
  #5 (permalink)  
Old December 13th, 2004, 01:19 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I recommend nl2br as an easy way to do this..

Code:
$new_actionplan = nl2br($_POST['ActionPlan']);
-Snib - http://www.snibworks.com
Where will you be in 100 years?
Reply With Quote
  #6 (permalink)  
Old December 14th, 2004, 05:25 AM
Authorized User
 
Join Date: Oct 2004
Location: Edinburgh, Scotland, United Kingdom.
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

ooh, nl2br, you learn something new every day ;)

Many shoes,

Jamez/SiliconFuRy
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Preg_replace not stripping exclamation marks Picabrillo Pro PHP 0 February 8th, 2007 01:30 PM
apostrophes or quotation marks crmpicco Javascript 6 March 21st, 2006 09:01 AM
Spurious Exclamation Marks patwadd VBScript 0 November 18th, 2004 02:03 PM
Drop down box and book marks pbhupal HTML Code Clinic 1 September 10th, 2004 09:23 PM
Indented paragraph ric Beginning VB 6 1 February 26th, 2004 06:08 AM



All times are GMT -4. The time now is 05:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.