Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 13th, 2004, 04:50 AM
Registered User
 
Join Date: Jul 2004
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.
 
Old December 13th, 2004, 05:10 AM
Authorized User
 
Join Date: Oct 2004
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
 
Old December 13th, 2004, 06:57 AM
Registered User
 
Join Date: Jul 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Jamez

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

Sameer
 
Old December 13th, 2004, 07:55 AM
Authorized User
 
Join Date: Oct 2004
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
 
Old December 13th, 2004, 01:19 PM
Friend of Wrox
 
Join Date: Nov 2003
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?
 
Old December 14th, 2004, 05:25 AM
Authorized User
 
Join Date: Oct 2004
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





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





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