By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,260 Members | 1,677 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,260 IT Pros & Developers. It's quick & easy.

Creating a forum - how to put '>' at start of quoted lines

P: n/a
Hi,
I'm trying to write a simple forum script and I want to include '>' at the
start of lines in quoted text (like on USENET). How do I go about doing
this? My post is stored in a MySQL DB text field. Also, if I use
strip_tags() to remove HTML from a post before putting it in the DB, how
can I retain < and > in the message and insert line breaks as typed (in
TEXTAREA)?

TIA,
- QS Computing.

--
QS Computing
http://www.qscomputing.plus.com
po********@qscomputing.plus.com
Jul 17 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On 2005-04-05, QS Computing <po********@qscomputing.plus.com> wrote:
I'm trying to write a simple forum script and I want to include '>' at the
start of lines in quoted text (like on USENET). How do I go about doing
this? My post is stored in a MySQL DB text field. Also, if I use
strip_tags() to remove HTML from a post before putting it in the DB, how
can I retain < and > in the message and insert line breaks as typed (in
TEXTAREA)?


How about &gt; ?

--
Cheers,
- Jacob Atzen
Jul 17 '05 #2

P: n/a
linebreaks --> php.net/nl2br

Jul 17 '05 #3

P: n/a
@Jacob Atzen: Do you mean users should insert '&gt;' when posting
instead of '<'?
Ideally, I'd like a quick way to convert '<' to '&gt;' in the text.

@frizzle: That's just what I'm looking for.

- QS Computing.

Jul 17 '05 #4

P: n/a
well, glad to help.

anyway, when you enter < and > into a db, just put them in there as
they are. When you get them out of the DB, use
http://php.net/htmlentities or http://php.net/htmlspecialchars.
This converts special chatacters to html-characters.

But as far as i know, you should always keep the data inside the DB
raw, and massage it as it comes out...

Good luck with it.

Jul 17 '05 #5

P: n/a
> But as far as i know, you should always keep the data inside the DB
raw, and massage it as it comes out...


I'd have thought that it would be the other way round - not sure why, but I
would have done. So if I run the text through nl2br() and htmlentities()
before writing it to the page, that will remove issues appearing through
using HTML?

I'm still stuck on inserting the >'s at the start of quoted lines. Is there
a function that will insert a character at the start of each line?

BTW, sorry - I forgot to say "thank you" in my last post! But thank you very
much anyway!!!

- QS Computing.

--
QS Computing
http://www.qscomputing.plus.com
po********@qscomputing.plus.com
Jul 17 '05 #6

P: n/a
As far as my little experience with DB's reaches, it's best to keep the
raw data (not converted to html yet) in the db, first of all, this
takes less space, and maybe you're going to need the data somewhere in
anon-html environment like textfiles, pdf whatever. Hope you understand
what i mean.

For your second question: because you need to insert a '>' at the
begining of each line, you need to define the length of a line, like 30
characters. If you don't do that, the page won't know where the browser
cuts the line, and where it has to insert the '>'.

Maybe you can use wordwrap (http://www.php.net/wordwrap):

$text = "A very long woooooooooooord.";
$new = wordwrap($text, 8, "<br>\n&gt;&nbsp;", 1);

echo "&gt;&nbsp;".$new;

gives:
A very
long
woooooooo
oooord.


Have a look at the wordwrapfunction, this could be just what you're
looking for...

Jul 17 '05 #7

P: n/a
frizzle wrote on Thursday 07 Apr 2005 10:58:
As far as my little experience with DB's reaches, it's best to keep the
raw data (not converted to html yet) in the db, first of all, this
takes less space, and maybe you're going to need the data somewhere in
anon-html environment like textfiles, pdf whatever. Hope you understand
what i mean.
OK - that all makes sense now.
Have a look at the wordwrapfunction, this could be just what you're
looking for...


Bingo! Just what I need - I can use that example almost as shown.

One last question - if I add a record to a DB with an autonumber field, how
can I get the value of that autonumber field straight afterwards?

Thanks,
- QS Computing.

--
QS Computing
http://www.qscomputing.plus.com
po********@qscomputing.plus.com
Jul 17 '05 #8

P: n/a
> Bingo! Just what I need

Just one problem though... if the original text is eg.
this
is
a
test

(with forced line breaks), then wordwrap() will return
this

is
a
test

I'd like to have the > at the start of all lines, not just the ones where it
wraps.

Any ideas?

Thanks,
- QS Computing.

--
QS Computing
http://www.qscomputing.plus.com
po********@qscomputing.plus.com
Jul 17 '05 #9

P: n/a
QS Computing wrote on Thursday 07 Apr 2005 19:31:
I'd like to have the > at the start of all lines, not just the ones where
it wraps.


Found a solution myself -
http://morannon.the-infinite.org/archive/php/word_wrap

Thank you for all your help.

--
QS Computing
http://www.qscomputing.plus.com
po********@qscomputing.plus.com
Jul 17 '05 #10

P: n/a
Well again, glad to help. Anyway, the value of autonumber:

if you're talking about the id of the record you just inserted, use
LAST_INSERT_ID,,

Good luck.

Jul 17 '05 #11

P: n/a
Thanks very much. All problems solved. You can see the finished product at
my website.
--
QS Computing
http://www.qscomputing.plus.com
po********@qscomputing.plus.com
Jul 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.