|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
Could you paste some of your code so we can see whats going on? Without a sample we can't give accurate direction..
Thanks. |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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> |
|
#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- |
|
#6
|
|||
|
|||
|
That's what it needed, KM! THANK YOU SO MUCH!
Thanks for all the help! Sintrigue |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Displaying text correctly |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|