PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

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:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old June 13th, 2004, 11:34 PM
sintrigue sintrigue is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 12 sintrigue User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Displaying text correctly

Hello,

This is my first attempt at writing a PHP script, please be patient. Any assistance is appreciated very much.

My code takes information entered into a text box (using an HTML form tag, text area) and saves the text into a database. The next phase of the script takes the data out of the database and displays the saved text. It works fine except the text that is displayed has no line feed/carriage returns anywhere.

Example, this is what I enter into the textarea form box:
This is line one of data.
This is line two of data.
This is line three of data.

Example, this is what is displayed when it is extracted from the database:
This is line one of data.This is line two of data.This is line three of data.

All on one line... Hmm.

Can someone please tell me how to correct this problem?

I apologize if I've missed some posting standard. I'm extremely new to this. (My first script/post)

Thanks so much,

Sintrigue

Reply With Quote
  #2  
Old June 14th, 2004, 09:57 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 52 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Could you paste some of your code so we can see whats going on? Without a sample we can't give accurate direction..

Thanks.

Reply With Quote
  #3  
Old June 14th, 2004, 10:33 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston 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 dhouston
You need to run either nl2br($variable_name) or preg_replace("/\n/","<br>",$variable_name) on the text from your database in order to convert line breaks to HTML <br> tags.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #4  
Old June 14th, 2004, 03:58 PM
sintrigue sintrigue is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 12 sintrigue User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the assistance. How would I run either of these commands? By assigning the content of the field into the variable? Would it then replace all of the instances?

Again, if I have posted out of form, my apologies. Thanks for the assistance!

The code to show the data is here:


<HTML>
<HEAD>
<TITLE>+ storypost +</TITLE>
</HEAD>
<body bgcolor="#99CCFF" background="background.jpg">
<p align="center"><img border="0" src="title.jpg"></p>
<br>
<?
$link = mysql_connect('localhost', 'databaseuser', 'bleedingheart');
if (!$link) {
die(The database could not be opened. Error: ' . mysql_error());
}
mysql_select_db("storypost");

$result = mysql_query('select storytitle, storytext from sptable');
if (!$result) {
die('The database could not be opened. Error: ' . mysql_error());
}

//Response.Write "<B><center>Sorry, there is no story currently posted!</center></B>"
?>
<br>
<hr size=2 width=80%>
<br>
<?
$num_rows = mysql_num_rows($result);
if($num_rows >0)
{
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<table border=0 cellpadding=2 cellspacing=0 width="100%">
<tr><td width=15%></td><td align=center><b><?echo $row["storytitle"]; ?></b></td><td width=15%></td></tr><br><br>
<tr><td width=15%></td><td valign=top><?echo $row["storytext"]; ?></td><td width=15%></td></tr>
<tr><td></td><td>
</td></tr>
</table>
<br>
<hr size=2 width=80%>
<br>
<?
}
}else
{
echo "<B><center>Sorry, there is no story currently posted!</center></B>";
}
mysql_free_result($result);
?>
</BODY>
</HTML>

Reply With Quote
  #5  
Old June 14th, 2004, 04:26 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
Where you have $row ['storytext'] you can pass this into the nl2br function and it will add in the <br /> tags for you. So the statement becomes -

<?echo nl2br ($row["storytext"]); ?>

Hope this helps,

-KM-

Reply With Quote
  #6  
Old June 14th, 2004, 04:28 PM
sintrigue sintrigue is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 12 sintrigue User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That's what it needed, KM! THANK YOU SO MUCH!
Thanks for all the help!

Sintrigue

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Displaying text correctly


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 5 hosted by Hostway