Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-05-2008, 11:53 AM nl2br() not working
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-05-2008, 11:59 AM Re: nl2br() not working
Plugin-Developer's Avatar
Weightlifting CS Student

Posts: 504
Name: Nick Ohrn
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
- Custom plugin development to fit your needs. Plugins available for WordPress and Drupal, among others.
Plugin-Developer is offline
Reply With Quote
View Public Profile Visit Plugin-Developer's homepage!
 
Old 05-05-2008, 01:16 PM Re: nl2br() not working
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
So how would I get it to update the $content part in $ecm2 ??
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 05-05-2008, 01:18 PM Re: nl2br() not working
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Try setting a value for $content before you include your file.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-07-2008, 10:42 AM Re: nl2br() not working
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
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! ><
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 05-07-2008, 06:32 PM Re: nl2br() not working
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 05-07-2008, 07:12 PM Re: nl2br() not working
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
No problem, glad it worked out.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Reply     « Reply to nl2br() not working
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 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.50307 seconds with 12 queries