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

Replacing - and not Replacing...

P: n/a
Hi all,

Been a long time since I've been here...

/me waves to all..

Ok - my conundrum..

I have a form where a user can enter text and BB codes...for example:

bold text

I then parse the form when submitted with something like this:

strContent = Replace(strContent, "", "<b>")
strContent = Replace(strContent, "
", "</b>")

Content is then written to the database, when displayed out comes the html.
If they want to edit the content again it goes through the parser again but
in reverse affectively and puts all the square brackets back in...

My problem is around the carriage returns...

At the moment I am replacing a vbCRLF with <br> - the problem is when they
have something like this:

[table]
[tr]
[td]my cell[/td][td]my second cell[/td]
[/tr]
[/table]

I get a load of <br>'s that I don't really want, and of course because the
table stuff in this case is replaced with the html for the table the <br>'s
appear above it pushing it down the page - nightmare...

What I am after I suppose is a way of being able to say - change a vbCRLF
for a <br> but only if it's not proceeding any of the following....

My initial thoughts were parse again - and remove and <br>'s if they are
joined to say any of the above tags...

strContent = Replace(strContent, "</tr><br>", "</tr>")

for example...but it's not pretty, it doesn't feel "clever" and would
require a load of additional parsing where mistakes could easily be made...

The square bracketting tags etc will remain regardless of how this is
resolved, so please no suggestions for css etc, but if anyone has any
'compatible' :) ideas please let me know.

Regards

Rob

Jul 22 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
I dont know RegEx that well but maybe only do your replace if the <br> is
after a ] and before a [/

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Rob Meade" <ro********@NO-SPAM.kingswoodweb.net> wrote in message
news:53****************@text.news.blueyonder.co.uk ...
Hi all,

Been a long time since I've been here...

/me waves to all..

Ok - my conundrum..

I have a form where a user can enter text and BB codes...for example:

bold text

I then parse the form when submitted with something like this:

strContent = Replace(strContent, "", "<b>")
strContent = Replace(strContent, "
", "</b>")

Content is then written to the database, when displayed out comes the
html. If they want to edit the content again it goes through the parser
again but in reverse affectively and puts all the square brackets back
in...

My problem is around the carriage returns...

At the moment I am replacing a vbCRLF with <br> - the problem is when they
have something like this:

[table]
[tr]
[td]my cell[/td][td]my second cell[/td]
[/tr]
[/table]

I get a load of <br>'s that I don't really want, and of course because the
table stuff in this case is replaced with the html for the table the
<br>'s appear above it pushing it down the page - nightmare...

What I am after I suppose is a way of being able to say - change a vbCRLF
for a <br> but only if it's not proceeding any of the following....

My initial thoughts were parse again - and remove and <br>'s if they are
joined to say any of the above tags...

strContent = Replace(strContent, "</tr><br>", "</tr>")

for example...but it's not pretty, it doesn't feel "clever" and would
require a load of additional parsing where mistakes could easily be
made...

The square bracketting tags etc will remain regardless of how this is
resolved, so please no suggestions for css etc, but if anyone has any
'compatible' :) ideas please let me know.

Regards

Rob

Jul 22 '05 #2

P: n/a
"Curt_C [MVP]" wrote ...
I dont know RegEx that well but maybe only do your replace if the <br> is
after a ] and before a [/


Hi Curt, thanks for the reply.

I am not overly familar with RegEx myself, but will take a look...I'm not
sure where I'll need to do the replaces anyway, as they could have this:

Hello Curt,

Welcome to our website.

Enjoy your visit.
So, that would look something like this:

Hello <b>Curt</b>,<br><br>Welcome to our website.<br><br>Enjoy <i>your</i>
visit.

In this case I'd want the vbCRLF's changed to <br>'s are the end of each
line, and on the blank lines, and obviously that wouldn't be between a ] and
a [/ etc...

Another difficulty are the tags that they can still enter html attributes
in...for example:

I enable them to have

[table] or [table ...]

with ... being whatever they want to enter, perhaps [table width="100"] when
I parse this its more difficult because you dont have a predetermined piece
of text, they could enter 300, 300%, 30000 for example...

Regards

Rob
Jul 22 '05 #3

P: n/a
Then you are probably going to have to train your users. I mean if they put
in a break then THEY put in a break. You are just doing what they want.

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Rob Meade" <ro********@NO-SPAM.kingswoodweb.net> wrote in message
news:Sp***************@text.news.blueyonder.co.uk. ..
"Curt_C [MVP]" wrote ...
I dont know RegEx that well but maybe only do your replace if the <br> is
after a ] and before a [/


Hi Curt, thanks for the reply.

I am not overly familar with RegEx myself, but will take a look...I'm not
sure where I'll need to do the replaces anyway, as they could have this:

Hello Curt,

Welcome to our website.

Enjoy your visit.
So, that would look something like this:

Hello <b>Curt</b>,<br><br>Welcome to our website.<br><br>Enjoy <i>your</i>
visit.

In this case I'd want the vbCRLF's changed to <br>'s are the end of each
line, and on the blank lines, and obviously that wouldn't be between a ]
and a [/ etc...

Another difficulty are the tags that they can still enter html attributes
in...for example:

I enable them to have

[table] or [table ...]

with ... being whatever they want to enter, perhaps [table width="100"]
when I parse this its more difficult because you dont have a predetermined
piece of text, they could enter 300, 300%, 30000 for example...

Regards

Rob

Jul 22 '05 #4

P: n/a
"Rob Meade" <ro********@NO-SPAM.kingswoodweb.net> wrote in message
news:53****************@text.news.blueyonder.co.uk ...
Hi all,

Been a long time since I've been here...

/me waves to all..

Ok - my conundrum..

I have a form where a user can enter text and BB codes...for example:

bold text

I then parse the form when submitted with something like this:

strContent = Replace(strContent, "", "<b>")
strContent = Replace(strContent, "
", "</b>")

Content is then written to the database, when displayed out comes the
html. If they want to edit the content again it goes through the parser
again but in reverse affectively and puts all the square brackets back
in...

My problem is around the carriage returns...

At the moment I am replacing a vbCRLF with <br> - the problem is when they
have something like this:

[table]
[tr]
[td]my cell[/td][td]my second cell[/td]
[/tr]
[/table]

I get a load of <br>'s that I don't really want, and of course because the
table stuff in this case is replaced with the html for the table the
<br>'s appear above it pushing it down the page - nightmare...

What I am after I suppose is a way of being able to say - change a vbCRLF
for a <br> but only if it's not proceeding any of the following....

My initial thoughts were parse again - and remove and <br>'s if they are
joined to say any of the above tags...

strContent = Replace(strContent, "</tr><br>", "</tr>")

for example...but it's not pretty, it doesn't feel "clever" and would
require a load of additional parsing where mistakes could easily be
made...

The square bracketting tags etc will remain regardless of how this is
resolved, so please no suggestions for css etc, but if anyone has any
'compatible' :) ideas please let me know.

Regards

Rob


Why don't you simply store the content as submitted, then parse to html when
you need to display? This is similar to data entered in textarea controls.
You don't insert <br> tags when you capture the data to a database, only
when you display it.
Jul 22 '05 #5

P: n/a
"Curt_C [MVP]" wrote ...
Then you are probably going to have to train your users. I mean if they
put in a break then THEY put in a break. You are just doing what they
want.


Users eh! *tut* :o)

If I did that though, the tables support for example to appear correctly
would have to be entered all on one line...a complex table layout would be
almost impossible to decipher if there was anything wrong with it, if they
enter it all on one line that's up to them, but my parsing I believe needs
to ignore the carriage returns in between table tags (opening and closing) -
when after cells and rows anyway...

Regards

Rob
Jul 22 '05 #6

P: n/a
"Chris Hohmann" wrote ...
Why don't you simply store the content as submitted, then parse to html
when you need to display?
Hi Chris, thanks for the reply.

I thought of this when I first starting writing it some 2+ years ago, the
site in question gets a reasonable amount of traffic each month, the biggest
I've worked on thus far, not necessarily huge in comparision to Amazon and
the like though, but still, I decided to parse once, store to SQL Server,
then on the displaying page all the app has to do is get the content and
dump to the page, no further formatting is needed because the CSS handles
the rest - if I did it the other way, *every* user would trigger a parse of
the content for every page - I figured this would cause a bit of a
performance over head.
This is similar to data entered in textarea controls. You don't insert
<br> tags when you capture the data to a database, only when you display
it.


Normally I'd agree with that, if it was just some text and some carriage
returns, but because they are entering all kinds of formatting in there as
well, bold, italics, lists, tables and the like that needs to be changed
anyway, so it all gets done in the one swoop..

Regards

Rob
Jul 22 '05 #7

P: n/a
"Rob Meade" <ro********@NO-SPAM.kingswoodweb.net> wrote in message
news:wX****************@text.news.blueyonder.co.uk ...
"Chris Hohmann" wrote ...
Why don't you simply store the content as submitted, then parse to html
when you need to display?


Hi Chris, thanks for the reply.

I thought of this when I first starting writing it some 2+ years ago, the
site in question gets a reasonable amount of traffic each month, the
biggest I've worked on thus far, not necessarily huge in comparison to
Amazon and the like though, but still, I decided to parse once, store to
SQL Server, then on the displaying page all the app has to do is get the
content and dump to the page, no further formatting is needed because the
CSS handles the rest - if I did it the other way, *every* user would
trigger a parse of the content for every page - I figured this would cause
a bit of a performance over head.
This is similar to data entered in textarea controls. You don't insert
<br> tags when you capture the data to a database, only when you display
it.


Normally I'd agree with that, if it was just some text and some carriage
returns, but because they are entering all kinds of formatting in there as
well, bold, italics, lists, tables and the like that needs to be changed
anyway, so it all gets done in the one swoop..

Regards

Rob


Ok. It looks like you have a few options here:
1. Create a complex de-parsing algorithm that distinguished between display
linebreaks and markup linebreaks. This methodology will never be foolproof.

2. Introduce an explicit break tag into your custom markup language, perhaps
"[b]"? This of course raises the question, "Why use a custom markup at all?
Why not simply use HTML to begin with?"

3. Save both the original text and the parsed text when inserting/updating
data. To improve performance, you could save the original and parsed text to
files and simply store file references in the database. Here's an article on
the merits of storing file references instead of the actual data. It focuses
on image files, but it actually applies to any large file:
http://aspfaq.com/show.asp?id=2149

HTH
-Chris Hohmann

Jul 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.