Current location: Hot Scripts Forums » Programming Languages » PHP » Line breaks not working


Line breaks not working

Reply
  #1 (permalink)  
Old 11-27-03, 12:24 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Line breaks not working

I'm putting together a php/mysql cookbook/recipe program. All works well except for one bug.
When enterting info from a form to add a recipe, for example the ingredients section, you naturally hit the carriage return after you add each ingredient, so that you go to the next line. This saves in mysql the same way. However, when I go to display the recipe, the ingredients do not have the line breaks in them. The output is failing to break the lines where it should. I have tried variations of

nl2br
$replText = ereg_replace("13","<br>",$ingredients);
$replText=str_replace("\n","<br>",$ingredients);

Nothing is working. I'm not sure if its where I'm placing these functions, or if its something in my php setup. I'm also wondering if I need to add something in the form itself. And is the stripslashes/addslashes command something to consider in doing this? Thnx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-27-03, 02:03 PM
fyrestrtr fyrestrtr is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
Check the stuff you are passing to the functions. If your text contains \\n -- then nl2br() won't work for you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-27-03, 03:34 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
The only thing being added is plain text.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-27-03, 06:36 PM
Stephen Stephen is offline
New Member
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Run what you're typing into the form via cat -A, it will probably produce surprising results.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-27-03, 07:04 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Not sure what you mean by "via cat -A"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 11-28-03, 11:13 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
when you want to display the field from mysql use something like this :
PHP Code:

echo stripslashes(nl2br($text)); 

of course if you didn't use addslashes() you don't need to strip them ..
but the important thing is when you want to 'print' the output use nl2br() ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 11-28-03, 01:12 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Thnx. I finally figured out where to actually put the nl2br function to get it to work, and blend it with the rest of my output. Works like a charm.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirection back to a page from form submit DAL Perl 11 03-21-05 03:45 PM
ASP not working in IIS5 on WinXP Pro cistate ASP 5 06-18-04 03:31 PM
Noob Questions Mitch PHP 4 11-05-03 06:04 PM
If/else statement working...but not working mdhall PHP 13 10-16-03 09:47 AM
Making second line of file a string Man Down PHP 2 06-26-03 09:03 PM


All times are GMT -5. The time now is 10:20 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.