Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: LorKorub on 26 November 2002, 16:40

Title: PHP/MySQL question
Post by: LorKorub on 26 November 2002, 16:40
I wrote my own guestbook script for a friend's web site I am doing, but I cannot seem to format the text from a textbox to get it to output properly on the "view guestbook" screen.  It writes on only one line, and pressing Return, Tab, etc. have no effect.

I tried adjusting the column width on the output table, but no effect either...

Any suggestions?
Title: PHP/MySQL question
Post by: flap on 26 November 2002, 18:51
You'll need to replace the newline characters in the text with <br>
Title: PHP/MySQL question
Post by: Master of Reality on 26 November 2002, 19:54
cant you replace it with the php with a /n ?
(i dont know... i am asking)
Title: PHP/MySQL question
Post by: voidmain on 27 November 2002, 00:28
After pulling my guestbook comments from the database here is what I do to insert a <BR> wherever there is a return:

Code: [Select]
Title: PHP/MySQL question
Post by: LorKorub on 28 November 2002, 13:59
Thanks guys...

void:  Your function worked, but since PHP 4.0+ they have come up with something much easier to use. It is called the nl2br function. Easy:

<?
    $text=mysql_result($blah,$i,"blah");
    $new_text=nl2br($text);

?>

Then just call $new_text where you want to use it, or pass whatever variable you want to nl2br and call it directly.
Title: PHP/MySQL question
Post by: voidmain on 28 November 2002, 14:03
Cool, less typing. I think I have all of my servers upgraded to 4+ now. Guess I'll have to do some changes on the BS guestbook.  (http://smile.gif)
Title: PHP/MySQL question
Post by: Kintaro on 28 November 2002, 14:13
void you should release source for all your stuff.
Title: PHP/MySQL question
Post by: voidmain on 28 November 2002, 14:39
I'll clean up the guestbook stuff and tar/gz it up and put it in the files section while recovering from my turkey dinner tomorrow (today). I have other stuff out there already (not on the voidmain site though).

I'm sure there are better guest books out there. That is something I hacked up in a couple of hours one day and it's functional so I use it. I'll put up some code for a database driven links page as well. Another 1 or 2 hour incarnation. Maybe some of you guys can add to it and make it much better. When I write stuff for myself I usually just do the bare minimum (as you can probably tell).
Title: PHP/MySQL question
Post by: TheQuirk on 28 November 2002, 23:24
quote:
Originally posted by void main:
I'll clean up the guestbook stuff and tar/gz it up and put it in the files section while recovering from my turkey dinner tomorrow (today). I have other stuff out there already (not on the voidmain site though).

I'm sure there are better guest books out there. That is something I hacked up in a couple of hours one day and it's functional so I use it. I'll put up some code for a database driven links page as well. Another 1 or 2 hour incarnation. Maybe some of you guys can add to it and make it much better. When I write stuff for myself I usually just do the bare minimum (as you can probably tell).



Or I can just give you the source code to what I use. But you know how to do it yourself =\
Title: PHP/MySQL question
Post by: LorKorub on 29 November 2002, 12:54
I can give you the source code for mine if you want.  Mine is pretty much like void main's, minus the URL part (but I can put that in for you if you'd like.)

It's really easy. I did mine in a few hours. Just got snagged on the text-formatting.
Title: PHP/MySQL question
Post by: voidmain on 29 November 2002, 13:03
Yeah, maybe yours or Quirk's would be the way to go. I haven't had time to clean up the code and package it up. I'm working on a new RedHat tip for the site at the moment, and trying to get 2.5.50 to compile.