Text Formatting - Query From MySQL
Moderator: General Moderators
-
Subliminal
- Forum Commoner
- Posts: 40
- Joined: Thu Oct 23, 2003 8:12 pm
Text Formatting - Query From MySQL
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...
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:
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
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
-
Subliminal
- Forum Commoner
- Posts: 40
- Joined: Thu Oct 23, 2003 8:12 pm
nl2br
nl2br
Totally Rocks.. Thanks. I didn't quit understand the first one...
Thanks a million guys
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!
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?
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?
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
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,
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:
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
You guys are awesome!
lets see if you know why this is happening
$date = date("Y M D");
lets see if you know why this is happening
$date = date("Y M D");
-
Subliminal
- Forum Commoner
- Posts: 40
- Joined: Thu Oct 23, 2003 8:12 pm
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);
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);
-
Subliminal
- Forum Commoner
- Posts: 40
- Joined: Thu Oct 23, 2003 8:12 pm
Humph...
Tried This... no go...
$my_date = date("yyyy-mm-dd");
$my_date = date("yyyy-mm-dd");
-
Paddy
- Forum Contributor
- Posts: 244
- Joined: Wed Jun 11, 2003 8:16 pm
- Location: Hobart, Tas, Aussie
- Contact:
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
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...
but if I have to statically define the date then I am way off...