Reply
nl2br() not working
Old 05-05-2008, 10:53 AM nl2br() not working
Gilligan's Avatar
DEAD Good Coder

Posts: 1,201
Name: Stefan
Location: London, UK
Trying to replace new lines from what the user enters in a textarea into the html code '<br/>'

Of course nl2br() was created for this very reason. Somehow its not working though.

PHP Code:
  $title $_POST['pgtitle'];
  
$heading $_POST['heading'];
  
$content $_POST['content'];
  
$content nl2br($content);
                                                            
  
$ecm2 preg_replace ('/\[title\](.*?)\[\/title\]/is''</p><h1>$1</h1><p>'$ecm2);
                        
   
$ecm2 preg_replace ('/\[b\](.*?)\[\/b\]/is''<strong>$1</strong>'$ecm2);
                        
   
$ecm2 preg_replace ('/\[i\](.*?)\[\/i\]/is''<em>$1</em>'$ecm2);
                        
   
$ecm2 preg_replace ('/\[u\](.*?)\[\/u\]/is''<u>$1</u>'$ecm2);
                        
   
$ecm2 preg_replace ('/\[img\](.*?)\[\/img\]/is''<img src="$1" alt="Image" />'$ecm2);
                        
   
$ecm2 preg_replace ('/\[url=(.*?)\](.*?)\[\/url\]/i''<a href="$1">$2</a>'$ecm2);
                        
    
$ecm2 htmlentities($ecm2);

     
$form $ecm2;

     echo 
'<form action="download.php" method="post"><textarea name="textarea" cols="80" rows="20">'.$form.'
                         </textarea><input type="hidden" name="filename" value="'
.$title.'">
                         <br><input type="submit" value="Download"></form>'

Some more info:

$form = $ecm2
$ecm2 is in a separate file which has been included on the top line of my whole php page.

$content
$content is part of $ecm2.

PHP Warnings
No warnings received from this script.

preg_replace
Is fully working
Gilligan is offline
Reply With Quote
View Public Profile
 
Sponsored Links (We share ad revenue):
 
Old 05-05-2008, 10:59 AM Re: nl2br() not working
nickohrn's Avatar
Weightlifting CS Student

Posts: 495
Name: Nick Ohrn
If $ecm2 is just a string and $content is just a string then updating $content will not update the part of $ecm2 that is defined by $content. Once the string is created by concatenating $content into it, all references to $content are lost.
__________________
NickOhrn.com - My personal haven of insight to offer the world.
Plugin-Developer.com - Custom plugin development to fit your needs. Plugins available for WordPress and Drupal, among others.
nickohrn is offline
Reply With Quote
View Public Profile Visit nickohrn's homepage!
 
Old 05-05-2008, 12:16 PM Re: nl2br() not working
Gilligan's Avatar
DEAD Good Coder

Posts: 1,201
Name: Stefan
Location: London, UK
So how would I get it to update the $content part in $ecm2 ??
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 05-05-2008, 12:18 PM Re: nl2br() not working
VirtuosiMedia's Avatar
Ultra Talker

Latest Blog Post:
Web Development Business Tips
Posts: 432
Try setting a value for $content before you include your file.
VirtuosiMedia is online now
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-07-2008, 09:42 AM Re: nl2br() not working
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 5,532
Name: Dan
Location: Swindon
I think you just need to change this bit:

PHP Code:
 $ecm2 preg_replace ('/\[title\](.*?)\[\/title\]/is''</p><h1>$1</h1><p>'$ecm2); 
</SPAN>

to

PHP Code:
 $ecm2 preg_replace ('/\[title\](.*?)\[\/title\]/is''</p><h1>$1</h1><p>'$content); 
</SPAN>


hope this helps

TP aprieciated

DAN! ><
__________________
Support Children's Cancer and Leukaemia Movement shop online at buy.at/calm ~ Calmcharity.org
PHP Code:
if($_POST == true && $help == true) { $tp++; } else { $e_hug == true 
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 05-07-2008, 05:32 PM Re: nl2br() not working
Gilligan's Avatar
DEAD Good Coder

Posts: 1,201
Name: Stefan
Location: London, UK
Sorry for not replying sooner.

VirtuosiMedia, setting the value for the string above the include actaully worked. Thanks a lot

Dan,
Don't get greedy with TP
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 05-07-2008, 06:12 PM Re: nl2br() not working
VirtuosiMedia's Avatar
Ultra Talker

Latest Blog Post:
Web Development Business Tips
Posts: 432
No problem, glad it worked out.
VirtuosiMedia is online now
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Sponsored Links (We share ad revenue):
 
Reply     « Reply to nl2br() not working
 

Thread Tools

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML


Page generated in 0.15001 seconds with 15 queries