Page 1 of 2

Text Formatting - Query From MySQL

Posted: Sat Nov 15, 2003 7:55 pm
by Subliminal
Hey,

I am trying to build a small messaging system for work, it has come along quite nicely except I don't know how to format text with carriage returns.

For example I am writing this and have used return twice so far. When you read this message it will have two carriage returns. On my messaging system it shows up as one long line upon being pulled from MySQL. Is this something that is setup in MySQL or when it is being inserted or pulled? Is there a way to do it other than using <p></p>

Sorry I am not making much sense but I think I got the point across.

Thanks in advance,

PS TOTAL NEWBIE...

Posted: Sat Nov 15, 2003 8:10 pm
by Paddy
You can break up a string using str_split.

http://au2.php.net/manual/en/function.str-split.php

Then you can just print the arrays. Use print_r if formatting is not too important.

http://au2.php.net/manual/en/function.print-r.php

Posted: Sun Nov 16, 2003 12:05 am
by Weirdan
[php_man]nl2br[/php_man]

nl2br

Posted: Sun Nov 16, 2003 1:34 pm
by Subliminal
nl2br
Totally Rocks.. Thanks. I didn't quit understand the first one... :-(

Thanks a million guys

Oh Wait!

Posted: Sun Nov 16, 2003 3:02 pm
by Subliminal
oh wait....
when I pull the data and put it in a text area all the <br /> tags are there... any way to get rid of them?

Posted: Sun Nov 16, 2003 3:53 pm
by infolock
it's probably due to you not closing a " or a ' correctly. If you can't find it, post the block of code where it's happening and we'll see if we can't find it. Also, if you are not sure where it's happening at, just try putting the word Bob before or after every BR, and wait to see Bob Appear. then just start deleting bob as you go and you'll find it.

Posted: Sun Nov 16, 2003 4:14 pm
by Subliminal
sorry i wasn't very clear...

inserting into mysql using nl2br works and displaying the data works perfectly. However when I want to edit the data I use a text area to dump the information from myswl into. But it also pulls the <br /> tags. Is there a way to filter out the <br /> tags (kinda like stripslashes?) but sitll keep the carriage returns in the text area??

Thanks,

Posted: Sun Nov 16, 2003 4:23 pm
by Paddy

Code: Select all

<?php
$str = "blah<br />blah";
$str = str_replace("<br />","",$str);
?>

Yeeee HA

Posted: Sun Nov 16, 2003 5:33 pm
by Subliminal
You guys are awesome!

lets see if you know why this is happening

$date = date("Y M D");

Posted: Sun Nov 16, 2003 5:48 pm
by Paddy
Could you be a bit more clear? I am not sure what you are asking or maybe I just haven't woken up yet. :)

Posted: Sun Nov 16, 2003 5:54 pm
by Subliminal
sorry - didn't preview first
w/ this query the date doesn't insert into mysql I checked the names of fields. date_created is date, null, 0000-00-00.

$my_date = date("Y M D");
$query = "INSERT INTO message_table (title, designation, message, date_created) VALUES ('$title', '$designation', '$message', '$my_date')";
mysql_query($query);

Posted: Sun Nov 16, 2003 5:56 pm
by Paddy
It is because $my_date needs to be in the format yyyy-mm-dd else it will just insert 0000-00-00 into the database which is the default.

Humph...

Posted: Sun Nov 16, 2003 6:06 pm
by Subliminal
Tried This... no go...

$my_date = date("yyyy-mm-dd");

Posted: Sun Nov 16, 2003 6:57 pm
by Paddy
You are replacing the characters with numbers right? Like today, at least where I am, would be

Code: Select all

<?php
$my_date = date("2003-11-17");
?>

ah nope

Posted: Sun Nov 16, 2003 7:23 pm
by Subliminal
Ah... no I am not... I guess I am mistaken... What would i use to time and datestamp something every time it is editted, I was planning on using date() and everytime I did an insert...
but if I have to statically define the date then I am way off...