Current location: Hot Scripts Forums » Programming Languages » PHP » bb codes?


bb codes?

Reply
  #1 (permalink)  
Old 11-02-04, 12:52 PM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
bb codes?

i have a problem with showing the posted messages 'as written'.. here if i press enter
the line changes
but only way i have got the line to change is by makeing the user type [br] witch is not good.. i use a textarea that is slashed (addslashes()) and inserted.. then to show it i unslash (stripslashes()) it and just echo..
anyone know how its done or what i do wrong?
thanks
Wille
Reply With Quote
  #2 (permalink)  
Old 11-02-04, 01:08 PM
rongge rongge is offline
Newbie Coder
 
Join Date: Oct 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
use the function 'nl2br()' in the code for show message.
__________________
<a href=http://www.w3cweb.com>http://www.w3cweb.com</a>

Last edited by rongge; 11-02-04 at 01:32 PM.
Reply With Quote
  #3 (permalink)  
Old 11-02-04, 01:20 PM
4n7hr4x 4n7hr4x is offline
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$text YOURTEXT.

$text str_replace("r/""<br>"$text);
$text str_replace("/n"",<br>"$text); 
this replaces new lines and returns with <br>, great isnt it.
Reply With Quote
  #4 (permalink)  
Old 11-02-04, 01:48 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
BTW if you gonna use 4n7hr4x's cide on a windows machine use this:
PHP Code:

$text str_replace("\r\n"",<br>"$text); 

also it's a backslash not a foward.
Reply With Quote
  #5 (permalink)  
Old 11-02-04, 05:43 PM
4n7hr4x 4n7hr4x is offline
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
either way works fine, eclipse is just one line shorter,
Reply With Quote
  #6 (permalink)  
Old 11-02-04, 06:08 PM
Deekay Deekay is offline
Newbie Coder
 
Join Date: Oct 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Uh, actully your method would make it double <br> on windows.
Reply With Quote
  #7 (permalink)  
Old 11-02-04, 06:09 PM
4n7hr4x 4n7hr4x is offline
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
i have never used windows, good to know.
Reply With Quote
  #8 (permalink)  
Old 11-02-04, 09:02 PM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
PHP Code:

$text YOURTEXT
$text str_replace("r/""<br>"$text); 
$text str_replace("/n"",<br>"$text); 
this replaces new lines and returns with <br>, great isnt it.
Quote:
either way works fine, eclipse is just one line shorter,
eclipse way is ok. but it won't work when the browser is *NIX compliant. it's safer to change only "\n" into '<br />' and then strip the rest "\r" for cross browser compatibility.

about your way 4n7hr4x, i just ask, have you tested it before? since the character "r/" and "/n" do not exist in ASCII table, the character won't be replaced except there is either literal 'r/' and '/n' in the string. (which is contrary to what is expected).

regards,
__________________
just an ignorant noob with moronic solution...
Reply With Quote
  #9 (permalink)  
Old 11-03-04, 01:31 PM
4n7hr4x 4n7hr4x is offline
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, I use it on my site
Reply With Quote
  #10 (permalink)  
Old 11-03-04, 02:56 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Deekay
Uh, actully your method would make it double <br> on windows.
Well it has worked for me on my windows server.....
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
Money for code, very short C++ codes for specific problems godzilla1 C/C++ 0 04-05-04 07:05 AM
VB Codes !!!HELP!!! !!!HELP!!! shaunchilling Visual Basic 1 04-01-04 06:39 AM
Paypal, strompay, check2out codes ilker HTML/XHTML/XML 2 02-16-04 10:41 AM


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