Text Formatting - Query From MySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Subliminal
Forum Commoner
Posts: 40
Joined: Thu Oct 23, 2003 8:12 pm

Text Formatting - Query From MySQL

Post 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...
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

[php_man]nl2br[/php_man]
Subliminal
Forum Commoner
Posts: 40
Joined: Thu Oct 23, 2003 8:12 pm

nl2br

Post by Subliminal »

nl2br
Totally Rocks.. Thanks. I didn't quit understand the first one... :-(

Thanks a million guys
Subliminal
Forum Commoner
Posts: 40
Joined: Thu Oct 23, 2003 8:12 pm

Oh Wait!

Post 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?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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.
Subliminal
Forum Commoner
Posts: 40
Joined: Thu Oct 23, 2003 8:12 pm

Post 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,
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Code: Select all

<?php
$str = "blah<br />blah";
$str = str_replace("<br />","",$str);
?>
Subliminal
Forum Commoner
Posts: 40
Joined: Thu Oct 23, 2003 8:12 pm

Yeeee HA

Post by Subliminal »

You guys are awesome!

lets see if you know why this is happening

$date = date("Y M D");
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post 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. :)
Subliminal
Forum Commoner
Posts: 40
Joined: Thu Oct 23, 2003 8:12 pm

Post 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);
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post 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.
Subliminal
Forum Commoner
Posts: 40
Joined: Thu Oct 23, 2003 8:12 pm

Humph...

Post by Subliminal »

Tried This... no go...

$my_date = date("yyyy-mm-dd");
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post 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");
?>
Subliminal
Forum Commoner
Posts: 40
Joined: Thu Oct 23, 2003 8:12 pm

ah nope

Post 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...
Post Reply